iphone - MPMoviePlayerController 性能受到影响

标签 iphone ios xcode mpmovieplayercontroller

我使用 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];

`

为什么应用程序停止? 这个问题有解决办法吗?

最佳答案

如果您查看 MPMoviePlayerController 的文档,您会发现在示例中,他们甚至在将电影播放器​​添加到 View 之前调用 prepareToPlay

我会在您设置播放器的位置添加[mediaPlayerprepareToPlay]

MPMediaPlayback Protocol Reference说: “为了最大限度地减少播放延迟,请在调用播放之前调用此方法”

关于iphone - MPMoviePlayerController 性能受到影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10986877/

相关文章:

ios - 在 App Transport Security 上引发异常?

iphone - XCode 7.3 ScrollView 和导航 Controller

ios - 递归方法 Objective-C

iphone - Cocos2d中的问题

android - Kotlin 多平台移动 : Flow<List<*SomeModel*>> gets mapped to Flow<NSArray> in iOS

ios - Array as a Table 是否易于使用?

ios - 无法存档应用

iphone - '+entityForName : nil is not a legal NSManagedObjectContext

iphone - 在默认日历中添加特定日期作为事件

iphone - 在 Safari 而不是 UIWebView 中打开 YouTube URL