2010-07-01 97 views
0

嗨,我已经创建了iPad的应用程序,它有一个资源文件夹中的视频文件,它播放时,用户单击播放按钮。 它适用于第一次用户点击播放按钮,但当用户播放视频文件的后续时间。问题发生的是视频不播放只有音频正在播放。这些问题不会随机发生,但会发生更多次。mpmovieplayercontroller问题ipad

在发生问题时还有一件事(视频不播放),当我点击位于播放器右下角的wo-arrow图标时,电影将全屏显示,并显示视频。在实时视频正在播放。

任何人都可以帮助我吗?

这是我的示例代码

MPMoviePlayerController *moviePlayer; 

} @property(读写,保留)的MPMoviePlayerController * moviePlayer; @synthesize moviePlayer;

- (void)viewDidLoad { 
[[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(movieFinishedCallback:) 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:self.moviePlayer]; 
[super viewDidLoad]; 
    } 


    -(IBAction)PlayBtnPressed:(id)sender 
{ 

NSURL *movieURL; 
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"title" ofType:@"mp4"]; 
movieURL = [NSURL fileURLWithPath:moviePath]; 
// Initialize a movie player object with the specified URL 
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
if (mp) 
{ 
    // save the movie player object 
    self.moviePlayer = mp; 
    [mp release]; 

    UIInterfaceOrientation orientation = [[UIDevice currentDevice]orientation]; 
    [self shouldAutorotateToInterfaceOrientation:orientation]; 
    // Play the movie! 
    [self.view addSubview:self.moviePlayer.view]; 
    [self.moviePlayer play]; 
} 
} 


    - (void) movieFinishedCallback:(NSNotification*) aNotification { 
    NSLog(@"movieFinishedCallback aNotification"); 
    MPMoviePlayerController *player = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:player]; 
    [player stop]; 
    [player.view removeFromSuperview]; 
    } 

在此先感谢........

回答

1

貌似movieplayer是没有得到释放,直到你分配的第二个在同一个电影文件后:

self.moviePlayer = mp; 

保留它,但影片结束部分没有做

self.moviePlayer = nil; 

可能是这是造成你的问题。