2013-03-28 168 views
0

我正在使用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上運行應用程序時變爲靜音。任何幫助將不勝感激。

回答

1

不看你的代碼。其中一個原因可能是您的iPhone處於靜音模式。

這個answer也可能幫助你。

+0

爲什麼我必須使用AVAudioSession!根據所有的教程MPMoviePlayer能夠做我想要的。據我所知,MPMoviePlayer可以播放.mp4,.3gp和.mov格式。但是,當我給.mp4/.3gp我的應用程序崩潰。對於.mov它播放,但沒有聲音。 MPMoviePlayer中的音頻有沒有我錯過的方法?!? – Esty 2013-03-28 12:45:47

相關問題