【问题标题】:AVAudioPlayer plays on silent mode when MPMoviePlayer plays播放 MPMoviePlayer 时,AVAudioPlayer 以静音模式播放
【发布时间】:2013-04-22 09:27:54
【问题描述】:

问题在于 AVAudioPlayer 本身的行为应如此。当设备不处于静音模式(静音/振铃开关打开)时,它会播放背景音乐。静音开关打开时,也尊重此状态,不播放背景音乐。

但是,当我在 MPMoviePlayer 中播放视频时,AVAudioPlayer 在静音模式下播放的一种特殊情况是。

在我的应用中,在播放电影之前首先播放 BG 声音。

有人可以帮忙吗?这只发生在我播放电影时。

其他详情:
使用 BG 循环 - m4a 类型
使用的电影类型 - m4v

我还发现这种情况在 iOS 5 中反复出现,但有时即使在最新版本中也会发生。

我在 Google、Apple 的文档和 SO 中到处都进行了研究,但我找不到关于这个特定场景的任何信息。

我什至尝试将 AVAudioSession 的类别显式设置为 AVAudioSessionCategoryAmbient,然后调用 setActive。 (也尝试了setCategory:withOptions:error 方法,但应用程序由于某种原因崩溃——在设备上测试)

当我尝试使用AVAudioPlayerDelegate时,我什至尝试设置委托和实现方法。

帮助任何人? :(

【问题讨论】:

    标签: iphone ios objective-c avaudioplayer mpmovieplayer


    【解决方案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>
    

    试试这样...

    【讨论】:

      【解决方案2】:

      尝试以这种方式设置音频会话

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-06
        • 2012-04-12
        相关资源
        最近更新 更多