1. 程式人生 > >ios 視訊播放

ios 視訊播放

NSString*path=[[NSBundle mainBundle] pathForResource:@"a" ofType:@"mp4"];
    NSURL *url=[NSURL fileURLWithPath:path];
    movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [movie prepareToPlay];
    movie.movieSourceType=MPMovieSourceTypeFile;
    movie.controlStyle = MPMovieControlStyleFullscreen;
    [movie.view setFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
    movie.initialPlaybackTime = -1;
    movie.controlStyle=MPMovieControlStyleNone;
    [self.view addSubview:movie.view];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];
    [movie play];

經反覆測試,支援mov、MP4格式的檔案,不管檔案大小。但是不支援mpg格式的檔案