声音只能通过MPMoviePlayerController在某些设备上通过耳机播放

Nic*_*aro 4 mpmovieplayercontroller ios iphone-4 ipad-2

我对你们都有一个奇怪的问题.

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];
}
Run Code Online (Sandbox Code Playgroud)

小智 5

这是一个古老的问题,但也许它会帮助某人.我遇到了同样的问题,发现只有手机处于静音模式时才会发生这种情况.

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

[theMoviePlayer setUseApplicationAudioSession:NO];
Run Code Online (Sandbox Code Playgroud)