ios 播放视频

播放视频时用到类MPMoviePlayerViewController,通过弹出模态窗口(全屏),播放视频。

MPMoviePlayerViewController类初始化时,用到一个NSURL类型的参数,如果是播放远程服务器上的视频,NSURL可直接初始化:

NSURL*videoPathURL=[NSURL URLWithString:urlStr];//urlStr是视频播放地址

如果是播放本地视频的话。这样初始化:

NSURL*videoPathURL=[[NSURL alloc] initFileURLWithPath:urlStr];


完整代码:

    MPMoviePlayerViewController*playViewController=[[MPMoviePlayerViewController alloc] initWithContentURL:videoPathURL];
    MPMoviePlayerController*player=[playViewController moviePlayer];
    player.scalingMode=MPMovieScalingModeFill;
    player.controlStyle=MPMovieControlStyleFullscreen;
    [player play];
    [self.navigationController presentViewController:playViewController animated:YES completion:nil];

你可能感兴趣的:(ios 播放视频)