objective-c - 更改 MPMoviePlayerController 实例的视频 url 而不是分配新的

标签 objective-c cocoa-touch ios mpmovieplayercontroller

我有一个名为 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;
}

我的应用程序中有两个 View ,名为 imageViewvideoView。我需要在 imageView 中隐藏 myMoviePlayer 并在我的 UI View 为 videoView 时再次显示它。

每次放映电影时,movieName 都会不同。

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

最佳答案

是的,有:

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

只需设置 contentURL propertyMPMoviePlayerController实例。

关于objective-c - 更改 MPMoviePlayerController 实例的视频 url 而不是分配新的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6129632/

相关文章:

objective-c - 将 NSAttributedString 转换为字符串并返回

ios - 使用串行蓝牙连接设备时出现问题

ios - 得到字符串 Url,但 url 有 "\/"。如何获取字符串中的每个正确值,如数组类型 swift3

ios - UIAlertView 动画卡住

objective-c - UIWebView 发布导致崩溃

iphone - 将多个 UIImages 插入到 "container"

ios - UITableView 删除部分 - 标题保持可见

objective-c - 为什么 UIViewController 没有加载我的 XIB 文件中的 View ?

iphone - 如何获取有关 UIScrollView 中页面的信息?

ios - Heyzap Ad Mediation,仅适用于 rootviewcontroller