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

Chr*_*ina 4 cocoa-touch objective-c mpmovieplayercontroller ios

我有一个MPMoviePlayerController名字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;
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序中有两个视图名为imageViewvideoView.我需要隐藏myMoviePlayerimageView,当我的UI视图是一次显示它videoView.

每次我放映电影,movieName都会有所不同.

现在,myVideoPlayer每次我的视图更改为电影视图时,我都会分配和初始化.是否可以在myMoviePlayer不重新分配的情况下设置新的视频网址?

Nic*_*ver 13

就在这里:

[myMoviePlayer setContentURL:[NSURL URLWithString:aMovieUrl]];
Run Code Online (Sandbox Code Playgroud)

只需设置的contentURL属性的的的MPMoviePlayerController实例.


Sun*_*uny 7

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

[myPlayer setContentURL:xyz];
[myPlayer play];
Run Code Online (Sandbox Code Playgroud)

请享用..!!