我有一个奇怪的问题。
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];
}
答案 0 :(得分:5)
这是一个古老的问题,但也许它会对某人有所帮助。我遇到了同样的问题,发现当手机只处于静音模式时就会发生这种情况。
解决方法是将播放器的useApplicationAudioSession属性设置为false。
[theMoviePlayer setUseApplicationAudioSession:NO];
答案 1 :(得分:0)
使用mpMoviePlayer在iPad 2上播放视频后,我遇到了这个问题。视频播放效果非常好,但音频仅在连接耳机时播放。
解决问题的解决方案:
[theMoviePlayer setUseApplicationAudioSession:NO];