播放视频

    //初始化url
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]];
   
    //初始化播放视频
    moviePlayer =[[MPMoviePlayerController alloc]initWithContentURL:url];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height*8/16);
    //控制模式
    moviePlayer.controlStyle=MPMovieControlStyleNone;
    //开始播放
    [moviePlayer play];
   
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

    [btn setTitle:@"" forState:UIControlStateNormal];
    btn.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height*8/16);
    [btn addTarget:self action:@selector(btnAct:) forControlEvents:(UIControlEventTouchUpInside)];
    btn.tag = 110;
   
//    moviePlayer.view.layer.transform=CATransform3DMakeRotation(M_PI, .5, 0, 1);
   
    [moviePlayer.view addSubview:btn];


   
   
}

- (void)btnAct:(UIButton *)btn{

    if (btn.selected) {
        [self play];
    }else{
        [self paush];
    }


   
}

- (void)play{
   
    UIButton *button = (UIButton*)[moviePlayer.view viewWithTag:110];
    button.selected = !button.selected;
    [moviePlayer play];
}
- (void)paush{
    UIButton *button = (UIButton*)[moviePlayer.view viewWithTag:110];
    button.selected = !button.selected;
    [moviePlayer pause];
   
}
 
button点击事件可以实现随意点击,实现播放,暂停功能

转载于:https://www.cnblogs.com/yxt9322yxt/p/4764346.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值