Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change video url for MPMoviePlayerController instance rather than allocating new one

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?

like image 216
Vipin Avatar asked Dec 01 '22 08:12

Vipin


1 Answers

Yes there is:

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

Just set the contentURL property of the MPMoviePlayerController instance.

like image 166
Nick Weaver Avatar answered Dec 04 '22 05:12

Nick Weaver