我正在下载一个 aac 文件并使用以下代码在 MPMoviePlayerController 中播放它
movieController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:self.filePath]];
[self.view addSubview:movieController.view];
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
movieController.view.frame = CGRectMake(0,0,screenSize.width, screenSize.height);
[movieController setFullscreen:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneBtnMediaPlayer:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
movieController 是(非原子、强)类属性
这在除 iOS 5(和 iOS 5 模拟器)之外的所有 iOS 中都可以正常工作。 在 iOS 5 中,它显示黑屏并且文件在后台播放。
我注意到的另一件事是,当我在现有应用程序上运行应用程序时,它在 iOS5 上也可以正常工作。但是当我从设备中删除应用程序然后运行它时,它只显示黑屏。
最佳答案
看看这是否有帮助:
这是您的头文件 (.h) #进口 #导入
@interface ViewController : UIViewController
@property(nonatomic,retain)MPMoviePlayerViewController *playerController;
@end
这是您的实现文件 (.m) #导入“ViewController.h”
@interface ViewController ()
@end
@implementation ViewController
@synthesize playerController;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"gold etche" ofType:@"mov"]];
playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[self.view insertSubview:playerController.view atIndex:0];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleDefault;
playerController.moviePlayer.scalingMode = MPMovieScalingModeNone;
[playerController.moviePlayer play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
我在 IOS 5(5.0 和 5.1)和 IOS 6 中对此进行了测试,一切似乎都很好
关于iphone - MPMoviePlayerController 仅在 iOS 5 中显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13742448/