【问题标题】:sound only playing through headphones on certain devices with MPMoviePlayerController仅在某些设备上使用 MPMoviePlayerController 通过耳机播放声音
【发布时间】:2012-02-09 02:42:29
【问题描述】:

我有一个奇怪的问题要问大家。

MPMoviePlayerController 视频播放正常,音频只能通过耳机播放。

真正的拖累是这只发生在一些 iPad 和 iPhone,即使是相同的型号 运行相同的系统!

我在这里创建了一个简单的失败示例:

http://www.porcaro.org/MPMoviePlayerController/TestMovie.zip

我已经看到它在 iPhone 4S、iPhone 4 和 iPad 2 上运行良好但失败了。

这是最相关的代码。感谢您提供任何见解,我也将向 Apple 提交一个错误:

(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    moviePath = [NSString stringWithFormat:@"%@/intro.m4v", [[NSBundle mainBundle] bundlePath]];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    controlStyle = MPMovieControlStyleEmbedded;
    movieView = [self view];
    movieRect = [[self view] frame];
    controlStyle = MPMovieControlStyleFullscreen;

    theMoviePlayer.controlStyle = controlStyle;
    theMoviePlayer.view.userInteractionEnabled = YES;

    if (1) {
        NSLog(@"Created theMoviePlayer: %@.  Playing: %@", theMoviePlayer, moviePath);
    }

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(checkForEndOfMovie:)
                                          name:MPMoviePlayerPlaybackStateDidChangeNotification
                                          object:theMoviePlayer];

    // this line doesn't fix the problem                                                                                                       
    //[theMoviePlayer prepareToPlay];                                                                                                          
    [[theMoviePlayer view] setFrame:movieRect];
    [movieView addSubview: [theMoviePlayer view]];
    [theMoviePlayer play];
}

【问题讨论】:

    标签: ios mpmovieplayercontroller iphone-4 ipad-2


    【解决方案1】:

    这是一个老问题,但也许它会对某人有所帮助。我遇到了同样的问题,发现它仅在手机处于静音模式时发生。

    解决方法是将播放器的useApplicationAudioSession属性设置为false。

    [theMoviePlayer setUseApplicationAudioSession:NO];
    

    【讨论】:

      【解决方案2】:

      这个问题曾经发生在我使用 mpMoviePlayer 在 iPad 2 上播放视频时。视频播放完美,但只有在连接耳机时才会播放音频。

      解决问题的办法:

      [theMoviePlayer setUseApplicationAudioSession:NO];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-20
        • 1970-01-01
        • 2011-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多