黑屏问题! [英] MPMoviePlayerViewController Black Screen issue!

查看:112
本文介绍了黑屏问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码试图在iPhone 4模拟器上运行视频。

I have this code trying to run a video on the iPhone 4 Simulator.

问题是,它看起来像加载播放器,但半秒后加载在整个应用程序顶部的屏幕上禁用触摸和一切,它看起来像不播放视频,因为我听不到任何东西。

The problem is that looks like it loads the player but half a second later loads a back screen on top of the whole application disabling touch and everything, and it looks like it does not play the video also, because I can't hear anything.

任何想法?!

MPMoviePlayerViewController *mp =
[[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];

if (mp) {
    mp.moviePlayer.scalingMode = MPMovieScalingModeFill; 
    mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [mp.moviePlayer play];

    [self presentMoviePlayerViewControllerAnimated:mp];

    [mp release];
}


推荐答案

通过释放MPMoviePlayerViewController。

I believe the problem is caused by releasing the MPMoviePlayerViewController. Simply retain the controller until you are done with it.

在[mp release];之前,添加此行以保存值。

Prior to the "[mp release];" add this line to save the value away.

self.moviePlayerViewController = mp;

然后更新您的dealloc方法来执行发布:

Then update your dealloc method to do the release:

- (void)dealloc {
   [_moviePlayerViewController release], _moviePlayerViewController = nil;
   [super dealloc];
}

将synthesize添加到.m文件的顶部:

Add the synthesize to the top of your .m file:

@synthesize moviePlayerViewController = _moviePlayerViewController;

将定义添加到.h文件的@interface:

Add the defination to the @interface of your .h file:

MPMovieViewController *_moviePlayerViewController;

将属性添加到.h文件中:

Add the property to your .h file:

@property (readwrite, retain) MPMovieViewController *moviePlayerViewController;

您的标头可能需要一些标题:

You may need some headers in your header:

#import <MediaPlayer/MediaPlayer.h>
#import <MediaPlayer/MPMoviePlayerViewController.h>

您可能还需要平衡presentMoviePlayer调用与dismiss:

You may also need to balance your "presentMoviePlayer" call with the dismiss somewhere:

[self dismissMoviePlayerViewControllerAnimated];

无论如何,如果你早完成资源,你可以通过使用NotificationManager更快地释放它来监视MPMoviePlayerPlaybackDidFinishNotification。有很多例子,所以我不再重复。

Phew, code everywhere. Anyway, if you are finished with the resource early, you may be able to release it sooner by using NotificationManager to watch for MPMoviePlayerPlaybackDidFinishNotification. There are many examples of that, so I won't repeat it.

希望这有帮助。

这篇关于黑屏问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆