我試圖在iPhone和iPod touch上播放音頻文件,其中包括AVAudioPlayer。該代碼工作正常iPhone和iPod touch 4G,我可以聽到音樂。但是當我測試它iPod touch 2G,iPod touch 3G,我什麼都聽不到。AVAudioPlayer在iPod touch 2G和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];