0

我正在下载一个 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 上也可以正常工作。但是当我从设备中删除应用程序然后运行它时,它只是显示黑屏。

4

1 回答 1

1

看看这是否有帮助:

这是你的头文件 (.h) #import #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 中对此进行了测试,一切似乎都很好

于 2012-12-06T13:59:05.680 回答