• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
那一季&花开
博客园    首页    新随笔    联系   管理    订阅  订阅

播放视频

    //初始化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点击事件可以实现随意点击,实现播放,暂停功能
posted @ 2015-08-27 19:25  那一季&花开  阅读(163)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3