0425 视频播放/MPMoviePlayerViewController与MPMoviePlayerController

MPMoviePlayerViewController
按钮中点击时间中:
   // s  = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//如果链接中有中文则需要转码
    NSURL *url = [NSURL URLWithString:s];
    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
   
// 注意MPMoviePlayerViewController是控制器对象
MPMoviePlayerController是继承于NSObject的对象,
本质不同,不要混淆了.
[self presentMoviePlayerViewControllerAnimated:mp];
 
注意:
// 如果是本地视频 , 用fileURLWithPath: 
 NSString *path = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"mp4"];
    //file://  http://
    url = [NSURL fileURLWithPath:path];
 

补充:
// 探索新方法
//
MPMoviePlayerViewController和MPMoviePlayerController.
// 不同点:
MPMoviePlayerController需要自己把自带的view用
setFrame的方法加到视图上.
测试MPMoviePlayerController写一个Demo看看:
OK 发现了另一种实现方式:
-(void)btnAction:(UIButton *)sender{
 
    NSString *s = @"http://hot.vrs.sohu.com/ipad1340910.m3u8";
   
   // s  = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
   
    NSURL *url = [NSURL URLWithString:s];
   
    if (_moviePlayer == nil) {
       
        _moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    }else {
        [_moviePlayer setContentURL:url];
    }
        // 控制选项,slider等
    _moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
   
    // 自动播放
    _moviePlayer.shouldAutoplay = YES;
    // 循环
    _moviePlayer.repeatMode = MPMovieRepeatModeOne;
    // 全屏
    [_moviePlayer setFullscreen:YES animated:YES];
    // 填充模式(跟图片填充模式相似)
内部链接:
图片显示模式(3种)
    _moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
   
    [_moviePlayer.view setFrame:self.view.frame];
// 两种都可以:

    //[_moviePlayer.view setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:_moviePlayer.view];
    [_moviePlayer play];
   
}
现在显示:
 
增加一段代码:
_moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
 
代码:
MPMoviePlayerController有各种设置,拉伸、控制模式、循环模式、自动播放等等,自己看着API文档

转载于:https://www.cnblogs.com/toxicanty/p/4456878.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值