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

发布于 2024-11-09 17:24:31 字数 874 浏览 0 评论 0原文

我有一个名为 myMoviePlayerMPMoviePlayerController;我在应用程序加载时分配并初始化它:

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 并在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆萌少年 2024-11-16 17:24:31

是的,有:

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

只需设置 contentURL 属性 href="http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html" rel="noreferrer">MPMoviePlayerController 实例。

Yes there is:

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

Just set the contentURL property of the MPMoviePlayerController instance.

摇划花蜜的午后 2024-11-16 17:24:31

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

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

享受..!!

Sharmain i got your problem...
you need to set the contentURL and then call Play method of mpmovieplayercontroller:

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

enjoy..!!

小耗子 2024-11-16 17:24:31
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];
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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文