-4

我尝试将视频添加到 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;
 }
4

1 回答 1

0

在 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];
    }
于 2013-06-17T09:01:23.460 回答