我正在下载一个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上的工作正常。但是,当我从设备中删除应用程序然后运行它时,它只显示黑屏。
答案 0 :(得分:1)
看看这是否有帮助:
这是您的标题(.h)文件 #进口 #import
@interface ViewController : UIViewController
@property(nonatomic,retain)MPMoviePlayerViewController *playerController;
@end
这是你的实现文件(.m) #import“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中测试了这一点,并且一切都很精致