2010-07-01 102 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; 

可能是這是造成你的問題。