我有一个名为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
而无需再次分配?
答案 0 :(得分:13)
是的,有:
[myMoviePlayer setContentURL:[NSURL URLWithString:aMovieUrl]];
答案 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];