【问题标题】:AVAudioPlayer plays music in iPod touch 2G and 3GAVAudioPlayer 在 iPod touch 2G 和 3G 中播放音乐
【发布时间】:2011-04-17 07:45:18
【问题描述】:

我正在尝试使用 AVAudioPlayer 在 iPhone 和 iPod touch 上播放音频文件。该代码在 iPhoneiPod touch 4G 中运行良好,我可以听到音乐。但是当我在 iPod touch 2GiPod touch 3G 上测试时,我什么也听不见。

下面是我用来播放音频文件的代码:

NSString *zeroAudioPath = [[NSBundle mainBundle] pathForResource:@"TimerBell"
                                                          ofType:@"aif"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:zeroAudioPath];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:file
                                                                    error:nil];
[file release];

self.zeroAudioPlayer = audioPlayer;
zeroAudioPlayer.delegate = self;
[audioPlayer release];
[zeroAudioPlayer prepareToPlay];
[zeroAudioPlayer play];

【问题讨论】:

    标签: ios avaudioplayer ipod-touch


    【解决方案1】:

    你应该在玩之前使用这样的音频会话:

    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:&error];
    

    【讨论】:

      【解决方案2】:

      我发现从kAudioSessionCategory_PlayAndRecord 更改为kAudioSessionCategory_AmbientSound 更正了这个问题。我怀疑这与 iPod touch 上与录音相关的硬件差异有关。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-29
        • 1970-01-01
        相关资源
        最近更新 更多