【问题标题】:MPMediaPlayer always crashesMPMediaPlayer 总是崩溃
【发布时间】:2013-06-17 08:12:04
【问题描述】:

我尝试向 Viewcontroller 添加视频但总是失败:有人可以帮忙吗?

-(id) init 
{ 
    // always call "super" init // Apple recommends to re-assign "self" with the "super's" return value 
     if(self=[super init]) 
     {
    //play // [[[CCDirector sharedDirector] view] addSubview:viewController.view];
     NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
     NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
     MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
     [viewController.view addSubview:moviePlayerController.view]; 
     moviePlayerController.fullscreen = YES;
     moviePlayerController.controlStyle = MPMovieControlStyleNone; 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDone:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController]; [moviePlayerController play];
     //play
    }
    return self;
 }

【问题讨论】:

标签: ios mpmediaplayercontroller


【解决方案1】:

在 ViewController.h 中

MPMoviePlayerController *moviePlayerController;

在 ViewController.m 中

 - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSString *filepath = [[NSBundle mainBundle] pathForResource:@"try" ofType:@"mp4"];
        NSURL *fileURL = [NSURL fileURLWithPath:filepath];
        moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
        [moviePlayerController.view setFrame:CGRectMake(0, 10, 320,300)];
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.fullscreen = YES;
        moviePlayerController.controlStyle=MPMovieControlStyleEmbedded;
        [moviePlayerController play];
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多