忘不了的石楠花 2015-12-18 08:03 采纳率: 0%
浏览 1601

视频播放抖动(播放一小段然后再从头播放完)

下面是放在pageViewController里面的子VC来播放视频。
模仿微信做的图片选择器,在浏览图片的时候,如果遇到视频,可以在浏览过程中播放视频。本人新手,希望遇到过这种情况的大神指教一下,谢谢了。

#import "CHVideoPlayerViewController.h"
#import

@interface CHVideoPlayerViewController ()
{
MPMoviePlayerViewController _movie;
UITapGestureRecognizer *_tap;
/
*
* 播放按钮
*/
UIImageView *_playerView;

}
@end

@implementation CHVideoPlayerViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

    _tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];

    /**

    • 视频播放对象 */ _movie = [[MPMoviePlayerViewController alloc] initWithContentURL:_url]; _movie.moviePlayer.controlStyle = MPMovieControlStyleNone; [_movie.view setFrame:self.view.bounds]; _movie.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; _movie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; _movie.moviePlayer.shouldAutoplay = NO; [_movie.view.subviews.firstObject addGestureRecognizer:_tap];

    _playerView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bofang64"]];
    _playerView.backgroundColor = [UIColor clearColor];
    // [_playerView addGestureRecognizer:_tap];
    _playerView.center = _movie.view.center;
    [_movie.view addSubview:_playerView];

    [self.view addSubview:_movie.view];

    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(myMovieFinishedCallback:)
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:nil];

}

  • (void)myMovieFinishedCallback:(NSNotification*)notification
    {
    _playerView.alpha = 1;
    self.navigationController.navigationBar.alpha = 0.5;
    self.navigationController.toolbar.alpha = 0.5;
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }

  • (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_movie.moviePlayer prepareToPlay];

    if (_movie.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
    self.navigationController.navigationBar.alpha = 0;
    self.navigationController.toolbar.alpha = 0;
    _playerView.alpha = 0;
    }else {
    self.navigationController.navigationBar.alpha = 0.5;
    self.navigationController.toolbar.alpha = 0.5;
    _playerView.alpha = 1;
    }

}

  • (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    }

  • (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [_movie.moviePlayer stop];
    }

  • (void)tapAction:(UITapGestureRecognizer *)tap {
    if (_movie.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
    [_movie.moviePlayer pause];
    self.navigationController.navigationBar.alpha = 0.5;
    self.navigationController.toolbar.alpha = 0.5;
    _playerView.alpha = 1;
    }else {
    self.navigationController.navigationBar.alpha = 0;
    self.navigationController.toolbar.alpha = 0;
    [UIView animateWithDuration:0.5 animations:^{
    _playerView.alpha = 0;
    _playerView.transform = CGAffineTransformMakeScale(5, 5);
    } completion:^(BOOL finished) {
    _playerView.transform = CGAffineTransformIdentity;
    [_movie.moviePlayer play];
    }];

    }
    }

  • 写回答

1条回答 默认 最新

  • devmiao 2016-02-13 23:28
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配