2012-09-11 78 views
2

我想從我的資源文件中加載25秒的mp4電影,但是當我播放它時,我的MPMoviePlayerPlaybackDidFinishNotification選擇器立即用MPMovieFinishReasonPlaybackEnded調用。當我登錄我的播放狀態時,顯示如下:MPMoviePlayerController立即結束

MPMoviePlaybackStatePlaying 
MPMoviePlaybackStatePaused 
MPMoviePlaybackStateStopped 
MovieFinishReasonPlaybackEnded 
MPMoviePlaybackStatePlaying 
MPMoviePlaybackStatePaused 

即使我只調用play方法一次。我希望有一個人可以幫助我。

- 編輯,以顯示我的代碼:

MPMoviePlayerController* player = [[[MPMoviePlayerController alloc] initWithContentURL:movieURL] autorelease]; 

if (player) 
{ 

    self.moviePlayerController = player; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayBackDidFinish:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:player]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayerPlaybackStateDidChange:) 
               name:MPMoviePlayerPlaybackStateDidChangeNotification 
               object:player]; 


    player.contentURL = movieURL; 

    player.movieSourceType = MPMovieSourceTypeFile; 

    player.controlStyle = MPMovieControlStyleNone; 

    player.fullscreen = YES; 

    switch (orientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
      player.view.transform = CGAffineTransformMakeRotation(90.0f * (M_PI/180.0f)); 
      break; 
     case UIInterfaceOrientationLandscapeRight: 
      player.view.transform = CGAffineTransformMakeRotation(-90.0f * (M_PI/180.0f)); 
      break; 
     default: 
      break; 
    } 

    player.view.frame = self.view.bounds; 

    [self.view addSubview:player.view]; 
} 

[self.moviePlayerController play] 

回答

0

而不必再聽你的代碼看,我建議嘗試播放,您知道還能再踢文件。例如,從這個示例項目中抓取電影:http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html並查看它是否播放。

當我試圖播放格式不正確的文件時,我遇到了類似的事情。


嗯......我看不出有什麼問題。你確定movieURL是正確的嗎?你如何得到它?

爲了記錄,這裏是我演示電影的方式,雖然它不會和你在做的事情有完全相同的效果。

NSString *path = [[NSBundle mainBundle] pathForResource:movieFileName ofType:@"m4v"]; 

// If path is NULL (the resource does not exist) return to avoid crash 
if (path == NULL) 
    return; 

NSURL *url = [NSURL fileURLWithPath:path]; 
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
mpViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 
mpViewController.moviePlayer.shouldAutoplay = YES; 

// NOTE: This can sometimes crash the app in the Simulator. This is a known bug 
// in xcode: http://stackoverflow.com/a/8317546/472344 
[self presentMoviePlayerViewControllerAnimated:mpViewController]; 
[mpViewController release]; 
+0

我試圖從鏈接Movie.m4v,它仍然無法正常工作。 – Jebadiah

+0

然後,您可能將不得不顯示您的代碼,以便任何人都可以幫助您。 – Darren

+0

只需編輯我的問題。謝謝。 – Jebadiah

1

self.moviePlayerController保留屬性?否則,MPMoviePlayerController實例將很快(由autorelease)發佈,您可能會得到類似的行爲。

相關問題