2012-02-09 77 views
4

我对你们所有人都有一个奇怪的问题。声音只能通过使用MPMoviePlayerController的某些设备上的耳机播放

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

真正的阻力是,这只是发生在一些 iPad和iPhone,甚至是完全相同的模型 运行完全相同的系统!

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

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

我见过它运行正常,并不能在iPhone 4S,iPhone 4和iPad 2

这里最相关的代码。感谢您的任何见解,我将提交错误,以苹果,以及:

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

回答

5

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

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

[theMoviePlayer setUseApplicationAudioSession:NO]; 
0

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

解决方案来解决这个问题:

[theMoviePlayer setUseApplicationAudioSession:NO]; 
相关问题