2011-05-25 63 views
4

我有一個MPMoviePlayerController,名爲myMoviePlayer;我分配和初始化它,當我的應用程序加載:更改MPMoviePlayerController實例的視頻url而不是分配新的

NSString *moviePath = [bundle pathForResource:[movieName uppercaseString] ofType:@"mov" inDirectory:@"Videos"]; 

if(moviePath) 
{ 
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath]; 

    myMoviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
    [**myUI.view** setFrame:CGRectMake(80, 80, 600, 350)]; 
    [self.view addSubview:myMoviePlayer.view]; 
    myMoviePlayer.shouldAutoplay=NO; 
} 

有我的應用程序兩種觀點名爲imageViewvideoView。我需要在imageView中隱藏myMoviePlayer,並在我的用戶界面視圖爲videoView時再次顯示。

我每次展示電影時,movieName都會有所不同。

現在,我每次將視圖更改爲影片視圖時,都會分配並初始化myVideoPlayer。是否可以設置一個新的視頻網址到myMoviePlayer而無需再次分配?

回答

13

是的,有:

[myMoviePlayer setContentURL:[NSURL URLWithString:aMovieUrl]]; 

只需設置MPMoviePlayerController實例的contentURL property

+0

問題只顯示與@Sharmain那麼這是開始一個新的視頻以正常的方式完全黑屏 – Christina 2011-05-25 19:55:25

+0

電影播放器​​,看看鏈接。視頻是否真的開始?我認爲需要一段時間來緩衝。 – 2011-05-25 19:58:54

+0

只顯示video.it只有當我點擊播放按鈕時纔會播放 – Christina 2011-05-25 20:01:27

7

Sharmain我收到了你的問題...... 你需要設置的contentURL,然後調用的MPMoviePlayerController的播放方法:

[myPlayer setContentURL:xyz]; 
[myPlayer play]; 

享受.. !!當我在第二次。它設置視頻播放器

0
NSString *path = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"]; 
self.myPlayer = [[MPMoviePlayerController alloc] init]; 
self.myPlayer.view.frame = CGRectMake(0, 124, 768, 900); 
self.myPlayer.shouldAutoplay = YES; 
self.myPlayer.controlStyle = MPMovieControlStyleNone; 
self.myPlayer.repeatMode = MPMovieRepeatModeOne; 
self.myPlayer.fullscreen = YES; 
self.myPlayer.movieSourceType = MPMovieSourceTypeFile; 
self.myPlayer.scalingMode = MPMovieScalingModeAspectFit; 
[self.view addSubview:myPlayer.view]; 

[myPlayer setContentURL:[NSURL fileURLWithPath:path]]; 
[myPlayer play]; 
相關問題