我的MP3播放代碼:AVAudioPlayer在模擬器的工作,但不是在設備
NSError *error;
soundObject = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:audioPathString] error:&error];
if (soundObject == nil) NSLog(@"%@", [error description]);
soundObject.delegate = self;
soundObject.numberOfLoops = 0;
soundObject.volume = 1.0;
NSLog(@"about to play");
[soundObject prepareToPlay];
[soundObject play];
NSLog(@"[soundObject play];");
用來玩細的MP3,它仍然沒有在模擬器上。但不在設備上。
我最近在軟件中添加了一些錄音代碼(不是我的)。它使用的AudioQueue東西略微超出了我的視野。這與AVAudioPlayer有衝突嗎?或者可能是什麼問題?我注意到,一旦audiorecording代碼開始工作,我不能再調整設備上的音量,所以它可能會阻止音頻播放?
編輯
的解決方案似乎是把這個在我的代碼。我把它的applicationDidFinishLaunching:
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
第一行同時允許播放和錄製,而其他線路改道顯然的事情,使音量大。
所有的音頻代碼對我來說都是巫術。
哪部分不起作用? – 2010-06-15 17:42:00
在設備上播放聲音不起作用。它在模擬器上工作。 – cannyboy 2010-06-15 17:53:23