0

我使用 MPMoviePlayerController 因为我想播放电影。

一个问题。当我创建 MPMoviePlayerController 时,应用程序会停止一点。

这是我的代码:

    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];

`

为什么应用程序停止?这是解决问题的方法吗?

4

2 回答 2

1

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"

于 2012-06-11T20:52:05.693 回答
0

我认为您可以使用多线程函数。

NSOperationQueue是线程安全的(你可以从不同的线程向它添加操作而不需要锁)并且使你能够将 NSOperation 对象链接在一起。

您可以使用以下代码快照来使用它们。

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

[queue addOperation:operation];

我希望这对你有帮助。

于 2012-06-11T20:32:18.380 回答