我今天花了一整天的时间让 MPMoviePlayerViewController 在 iOS5 上工作,但无论如何我都无法让它工作!以下代码在 iOS 5.0 以外的任何 iOS 上都可以正常工作。无法获得与此主题相关的太多帮助。谁能知道 iOs 5.0 中发生了什么变化,导致以下简单的代码爆裂!我注意到在 iOS 5.0 上,它会无限循环检查加载状态到 MPMovieLoadStateUnknown!它永远不会变成可玩的!
#import "MyMoviePlayer.h"
@implementation MyMoviePlayer
@synthesize moviePlayerViewController;
- (void) checkAndPlay:(UIViewController *)view {
if ([[moviePlayerViewController moviePlayer] loadState] == MPMovieLoadStateUnknown) {
NSLog(@"Rechecking");
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkAndPlay:) userInfo:nil repeats:NO];
} else {
[moviePlayerViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[view presentModalViewController:moviePlayerViewController animated:YES];
}
}
- (void)play:(NSURL*)movieURL andWithView:(UIViewController *)view {
moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self checkAndPlay:view];
}