更改MPMoviePlayerController实例的视频URL而不是分配新的实例

时间:2011-05-25 19:16:13

标签: objective-c cocoa-touch ios mpmovieplayercontroller

我有一个名为MPMoviePlayerController的{​​{1}};我在我的应用加载时分配并初始化它:

myMoviePlayer

我的应用中有两个名为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; } imageView的观点。我需要在videoView中隐藏myMoviePlayer,并在我的用户界面视图为imageView时再次显示。

每次播放电影时,videoView都会有所不同。

现在,每次我的视图更改为电影视图时,我都会分配和初始化movieName。是否可以将新的视频网址设置为myVideoPlayer而无需再次分配?

3 个答案:

答案 0 :(得分:13)

是的,有:

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

只需设置contentURL property个实例的MPMoviePlayerController

答案 1 :(得分:7)

Sharmain我遇到了你的问题...... 你需要设置contentURL,然后调用mpmovieplayercontroller的Play方法:

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

享受.. !!

答案 2 :(得分: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];