码迷,mamicode.com
首页 > 其他好文 > 详细

播放视频

时间:2015-08-27 20:49:58      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

    //初始化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点击事件可以实现随意点击,实现播放,暂停功能

播放视频

标签:

原文地址:http://www.cnblogs.com/yxt9322yxt/p/4764346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!