[英]MPMoviePlayerController shows only a black screen
我正在嘗試在啟動屏幕顯示后直接播放視頻,但是我所看到的一切都是黑屏,狀態欄顯示在頂部。 目前,這是應用程序的全部操作,因此據我所知,沒有任何其他事情可以停止視頻播放。
視頻可以在iPad上正常播放,而且格式正確,依此類推。 我的目標是iOS 7,並且嘗試使用其他視頻,也嘗試使用MPMoviePlayerViewController。 所有結果都相同。
這是我正在使用的代碼。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:@"IntroMovie" withExtension:@"mov"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[moviePlayer prepareToPlay];
[self.window addSubview:moviePlayer.view];
[moviePlayer play];
return YES;
}
您需要創建MPMoviePlayerViewController對象而不是前一個對象。playMovie方法應在makeKeyAndVisible之后調用。如果仍然不起作用,請嘗試添加斷點並檢查給定視頻的URL是否正確以及是否已將其添加到復制捆綁包資源。希望有幫助
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self playMovie];
return YES;
}
-(void)playMovie
{
NSURL *movieURL;
NSBundle *bundle = [NSBundle mainBundle];
if(bundle != nil)
{
NSString *moviePath = [bundle pathForResource:@"intro" ofType:@"m4v"];
if (moviePath)
{
movieURL = [NSURL fileURLWithPath:moviePath];
}
}
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.moviePlayer.scalingMode = MPMovieScalingModeFill;
[self.viewController presentViewController:moviePlayer animated:NO completion:^{
}];
[moviePlayer.moviePlayer play];
}
假設您沒有錯別字並且沒有正確的項目設置,那么您可能唯一的問題是在用於創建“ mov”文件的編解碼器內部。 嘗試使用其他一些mov文件,或嘗試將mov文件放入手機庫中並嘗試從那里播放
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.