为什么视频在iPhone的MPMoviePlayer上没有声音播放
问题描述:
我正在使用MPMoviePlayer在我的应用程序中播放本地视频文件。文件是.mov格式。当我在模拟器中运行我的应用程序时,它工作正常。但是当我在没有声音的iPhone视频中运行它时。这是我的代码,为什么视频在iPhone的MPMoviePlayer上没有声音播放
self.currUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Gun_Shot" ofType:@"mov"]];
if (self.mpc)
{
[self.mpc release];
self.mpc = nil;
}
self.mpc = [[MPMoviePlayerController alloc]
initWithContentURL:self.currUrl];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.mpc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidEnterFullScreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:self.mpc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:self.mpc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackNowPlayingContinues:) name:MPMoviePlayerNowPlayingMovieDidChangeNotification object:self.mpc];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.mpc];
self.mpc.controlStyle = MPMovieControlStyleNone;
self.mpc.shouldAutoplay = NO;
self.mpc.view.frame = CGRectMake(0, 0, self.mpView.frame.size.width, self.mpView.frame.size.height);
[self.mpView addSubview:self.mpc.view];
[self.mpView bringSubviewToFront:self.topMainView];
[self.mpView bringSubviewToFront:self.bottomMainView];
[self.mpc prepareToPlay];
self.timeLbl.text = [NSString stringWithFormat:@"%f Sec(s)", self.mpc.duration];
我不明白为什么视频在iPhone上运行应用程序时变为静音。任何帮助将不胜感激。
为什么我必须使用AVAudioSession!根据所有的教程MPMoviePlayer能够做我想要的。据我所知,MPMoviePlayer可以播放.mp4,.3gp和.mov格式。但是,当我给.mp4/.3gp我的应用程序崩溃。对于.mov它播放,但没有声音。 MPMoviePlayer中的音频有没有我错过的方法?!? – Esty 2013-03-28 12:45:47