4

我有一个奇怪的问题给你们。

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

2 回答 2

5

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

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

[theMoviePlayer setUseApplicationAudioSession:NO];
于 2012-09-30T00:59:33.557 回答
0

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

解决问题的解决方案:

[theMoviePlayer setUseApplicationAudioSession:NO];
于 2013-03-21T07:37:28.450 回答