Osushi
Osushi

Reputation: 107

MPMoviePlayerController Performance Hit

I use MPMoviePlayerController because I want to play movie.

One question. When I create MPMoviePlayerController, the app stops a little.

This is my code:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"m4v"];
    NSURL *videoURL = [NSURL fileURLWithPath:path];

    moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    moviePlayer.scalingMode=MPMovieScalingModeFill;
    moviePlayer.controlStyle=MPMovieControlStyleNone;
    moviePlayer.shouldAutoplay=NO;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieRestartCallback:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:nil];

    [moviePlayer.view setFrame:CGRectMake(20, 20, 280, 200)];
    [self.view addSubview:moviePlayer.view];

`

Why does the app stop? Is this problem resolution the way?

Upvotes: 0

Views: 1159

Answers (2)

Pei
Pei

Reputation: 11643

I think that you can use multi-threading functions.

NSOperationQueue is thread safe (you can add operations to it from different threads without the need for locks) and enables you to chain NSOperation objects together.

You can use following code snap to use them.

NSOperationQueue *queue = [NSOperationQueue mainQueue];
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
    // your code here
}];

[queue addOperation:operation];

I hope that is helpful to you.

Upvotes: 0

thelaws
thelaws

Reputation: 8001

If you look at the docs for MPMoviePlayerController you'll see that in the example they call prepareToPlay before even adding the movie player to the view.

I would add [mediaPlayer prepareToPlay] where you're setting up the player.

MPMediaPlayback Protocol Reference says: "to minimize playback delay, call this method before you call play"

Upvotes: 1

Related Questions