在iOS开发中,播放视频通常有两种方式,一种是使用MPMoviePlayerController(需要导入MediaPlayer.Framework),还有一种是使用AVPlayer。总体来说,MPMoviePlayerController使用更简单,功能不如AVPlayer强大,而AVPlayer使用稍微麻烦点,不过功能更加强大。根据需求进行两种控件的选择使用。
此文只涉及AVPlayer的使用,demo地址在最下面。
在开发中,单纯使用AVPlayer类是无法显示视频的,要将视频层添加至AVPlayerLayer中,这样才能将视频显示出来。
自定义一个UIView作为播放器。
/**
* 单纯使用AVPlayer类是无法显示视频,要将视频层添加至AVPlayerLayer中
*/
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface PlayerView : UIView
@property (strong,nonatomic) AVPlayer *player;
@end
自定义了一个UIView来设置播放器的其他功能。(MovieShowView)
将此MovieShowView放到VC当中,主要是想要做的功能完善一点,尽量进行封装。
此demo过程中,难点在于点击按钮之后的转屏设置。
不多赘叙程序,只强调技术点。
AVPlayerItem
playerItem的status有三种状态:AVPlayerStatusUnknown, //未知
AVPlayerStatusReadyToPlay,//可以播放
AVPlayerStatusFailed //失败
======
CMTime
CMTimeMake(a,b) // a当前第几帧, b每秒钟多少帧.当前播放时间a/b
CMTimeMakeWithSeconds(a,b) // a当前时间,b每秒钟多少帧.
=====
KVO模式监督视频播放状态
=====
UISwipeGestureRecognizer 和 UITapGestureRecognizer
======
动画旋转
CGAffineTransform
======
view停靠 autoresizingMask
======
屏幕状态条
[[UIApplication sharedApplication] setStatusBarOrientation:
UIInterfaceOrientationLandscapeRight animated:YES];
======
#import <MediaPlayer/MediaPlayer.h>
来使用MPVolumeView用于控制音量
觉得没有太大的必要,没能实现,有兴趣的自行加入吧!
========
DEMO地址:https://github.com/Lian1990/VideoLearnDemo
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。