Unable to play MP4 video file from mainBundle

前端 未结 7 584
挽巷
挽巷 2020-12-15 05:13

So I\'m trying to play a simple intro animation video file that I\'ve dragged into my project in XCode and therefore should be able to play from my mainBundle, right?

<
7条回答
  •  粉色の甜心
    2020-12-15 05:31

    Your code isn't correct. Please change accordingly to the following. Still copy your video into your bundle resources.

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"MacBook Pro with Retina Display" ofType:@"m4v"]];
    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
                                                     initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:playercontroller];
    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [playercontroller.moviePlayer play];
    [playercontroller release];
    playercontroller = nil;
    NSLog(@"Video is Playing");
    

提交回复
热议问题