2013-04-22 128 views
0

問題在於AVAudioPlayer本身的行爲與其應該一樣。當設備不處於靜音模式時(無聲/振鈴開關打開),它播放背景音樂。靜音開關打開時,它也會遵守此狀態並且不播放背景音樂。
當MPMoviePlayer播放時,AVAudioPlayer在靜音模式下播放

但是,AVAudioPlayer在靜音模式下播放的一個特殊場景是當我在MPMoviePlayer中播放視頻時。

在我的應用程序中,在播放電影之前先播放BG聲音。

任何人都可以幫忙嗎?這隻發生在我玩電影時。

對於其他細節:
BG循環使用 - M4A型使用
電影類型 - M4V

我還發現,這個場景反覆表面iOS 5中,但有時在最新版本中,甚至發生。

我在Google,蘋果公司的文檔和所有地方都在研究,但是在這個特定的場景中我找不到任何東西。

我甚至試着明確地將AVAudioSession的類別設置爲AVAudioSessionCategoryAmbient,然後調用setActive。 (也嘗試了setCategory:withOptions:error的方法,但由於某種原因的應用程序崩潰 - 在設備上測試)

我甚至嘗試設置委託和實施方法,當我試圖使用AVAudioPlayerDelegate

幫助任何人? :(

回答

1
NSURL *url = [NSURL URLWithString:self.videoURL]; 
      MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
      NSError *_error = nil; 
      [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &_error]; 
      [self presentMoviePlayerViewControllerAnimated:mpvc]; 

加入這一框架

#import <AVFoundation/AVFoundation.h> 

嘗試像這樣...

1

嘗試以這種方式

AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
     NSError *err = nil; 
     [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err]; 
     if(err){ 
      NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]); 
      return; 
     } 
     [audioSession setActive:YES error:&err]; 
     err = nil; 
     if(err){ 
      NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]); 
      return; 
     } 
設置音頻會議
相關問題