簡體   English   中英

當MPMoviePlayer播放時,AVAudioPlayer在靜音模式下播放

[英]AVAudioPlayer plays on silent mode when MPMoviePlayer plays

問題是AVAudioPlayer本身表現得如此。 當設備未處於靜音模式時(靜音/振鈴開關打開),它會播放背景音樂。 當靜音開關打開時,它也會尊重此狀態並且不播放背景音樂。

但是,AVAudioPlayer在靜音模式下播放的一個特殊情況是我在MPMoviePlayer中播放視頻。

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

有人可以幫忙嗎? 這只發生在我播放電影時。

其他細節:
BG Loop使用 - m4a型
使用的電影類型 - m4v

我還發現這個場景在iOS 5中反復出現,但有時甚至會在最新版本中出現。

我已經在Google,Apple的文檔和SO中隨處可見,但我找不到任何關於這個特定場景的內容。

我甚至嘗試將AVAudioSession的類別顯式設置為AVAudioSessionCategoryAmbient,然后調用setActive。 (還嘗試了setCategory:withOptions:error方法,但應用程序因某些原因崩潰 - 在設備上測試)

當我嘗試使用AVAudioPlayerDelegate時,我甚至嘗試設置委托和實現方法。

幫助任何人? :(

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>

試試這樣......

嘗試以這種方式設置音頻會話

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;
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM