views:

33

answers:

1

I have any number of thumbnail images that, when tapped, will play a different video (fullscreen). I have never been clear on whether I should keep one MPMoviePlayerController object in my view controller and have it play whichever url according to the thumbnail that was tapped, or create a new MPMoviePlayerController each time. What is the best practice?

I am also having problems where tapping on different thumbs crashes the app, I believe because the MPMoviePlayerController tries to stream a video while it is already trying to stream. There seems to be no way to cancel a MPMoviePlayerController and clear out what it was doing, then start loading a new video.

Here's how I create it:

MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];

Then to play a video I do this:

//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];

Any advice is welcome... thanks.

A: 

if you are you using 2 different view-controller one for selecting images and another for playing selected movie is full screen then go for 1st approach.

MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init]; self.player = moviePlayer; [moviePlayer release];

Avoid keeping player instance in memory if it is not needed.

if you using one view controller both for selection of images and playing video then go for second method

self.player.contentURL = someURL;

[self.view addSubview:player.view];

[self.player prepareToPlay];

[self.player play];

Avoid recreation of player it takes time...

jeeva