更改 MPMoviePlayerController 实例的视频 url,而不是分配新的
我有一个名为 myMoviePlayer
的 MPMoviePlayerController
;我在应用程序加载时分配并初始化它:
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
的视图。我需要在 imageView
中隐藏 myMoviePlayer
并在我的 UI 视图为 videoView
时再次显示它。
每次放映电影时,movieName
都会不同。
现在,每次我的视图更改为电影视图时,我都会分配并初始化 myVideoPlayer
。是否可以将新的视频 url 设置为 myMoviePlayer
而无需再次分配?
I have an MPMoviePlayerController
named myMoviePlayer
; I allocate and initialize it when my app loads:
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;
}
There are two views in my app named imageView
and videoView
. I need to hide myMoviePlayer
in imageView
and display it again when my UI view is videoView
.
Each time I show a movie, movieName
will be different.
Right now, I am allocating and initializing myVideoPlayer
each time my view changes to the movie view. Is it possible to set a new video url to myMoviePlayer
without allocating it again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,有:
只需设置 contentURL 属性 href="http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html" rel="noreferrer">MPMoviePlayerController 实例。
Yes there is:
Just set the contentURL property of the MPMoviePlayerController instance.
Sharmain 我遇到了你的问题...
您需要设置 contentURL,然后调用 mpmovieplayercontroller 的 Play 方法:
享受..!!
Sharmain i got your problem...
you need to set the contentURL and then call Play method of mpmovieplayercontroller:
enjoy..!!