ios avplayer 视频播放器

#import <UIKit/UIKit.h>

@interface XGGesTuresView : UIView

//左下角播放按钮

@property (nonatomic ,strong)UIButton                * leftplayerbutton;

//最小时间

@property (nonatomic ,strong)UILabel                 * mintimelable;

//滑动条

@property (nonatomic ,strong)UISlider                * slider;

//缓冲条

@property (nonatomic ,strong)UIProgressView          * progressview;

//视频总时长

@property (nonatomic ,strong)UILabel                 * maxtimelable;

//全屏按钮

@property (nonatomic ,strong)UIButton                * fullbutton;

//右边中间播放按钮

@property (nonatomic ,strong)UIButton                * rightplayerbutton;

//小菊花

@property (nonatomic ,strong)UIActivityIndicatorView * activity;

//视频出错提示  网络提示 用同一个

//@property (nonatomic ,strong)UILabel                 * errorlable;

//返回按钮

@property (nonatomic ,strong)UIButton                * backbutton;

//标题 可以自己调颜色

@property (nonatomic ,strong)UILabel                 * titlelable;

@end

#import "XGGesTuresView.h"

@implementation XGGesTuresView

- (instancetype)initWithFrame:(CGRect)frame{

if (self =[super initWithFrame:frame]) {

self.backgroundColor = [UIColor clearColor];

[self creatUI];

}

return self;

}

- (void)creatUI{

//左边播放按钮

self.leftplayerbutton  = [UIButton buttonWithType:UIButtonTypeCustom];

[self.leftplayerbutton setImage:[UIImage imageNamed:@"Stop"] forState:UIControlStateNormal];

[self.leftplayerbutton setImage:[UIImage imageNamed:@"Play"] forState:UIControlStateSelected];

[self addSubview:self.leftplayerbutton];

//进度时间lable

self.mintimelable               = [[UILabel alloc]init];

self.mintimelable.text          = @"00:00";

self.mintimelable.textColor     = [UIColor whiteColor];

self.mintimelable.textAlignment = NSTextAlignmentCenter;

self.mintimelable.font          = [UIFont systemFontOfSize:14];

[self addSubview:self.mintimelable];

//缓冲条

self.progressview                   = [[UIProgressView alloc]init];

self.progressview.progressTintColor = [UIColor magentaColor];

[self addSubview:self.progressview];

//滑动条

self.slider                       = [[UISlider alloc]init];

self.slider.minimumTrackTintColor = [UIColor whiteColor];

self.slider.maximumTrackTintColor = [UIColor clearColor];

[self.slider setThumbImage:[UIImage imageNamed:@"icmpv_thumb_light"] forState:UIControlStateNormal];

[self addSubview:self.slider];

//总时间lable

self.maxtimelable               = [[UILabel alloc]init];

self.maxtimelable.text          = @"00:00";

self.maxtimelable.textColor     = [UIColor whiteColor];

self.maxtimelable.textAlignment = NSTextAlignmentCenter;

self.maxtimelable.font          = [UIFont systemFontOfSize:14];

[self addSubview:self.maxtimelable];

//全屏按钮

self.fullbutton        = [UIButton buttonWithType:UIButtonTypeCustom];

[self.fullbutton setImage:[UIImage imageNamed:@"Rotation"] forState:UIControlStateNormal];

[self addSubview:self.fullbutton];

//右边播放按钮

self.rightplayerbutton = [UIButton buttonWithType:UIButtonTypeCustom];

[self.rightplayerbutton setImage:[UIImage imageNamed:@"player_pause_iphone_window"] forState:UIControlStateNormal];

[self.rightplayerbutton setImage:[UIImage imageNamed:@"player_start_iphone_window"] forState:UIControlStateSelected];

[self addSubview:self.rightplayerbutton];

//小菊花

self.activity        = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

self.activity.color  = [UIColor whiteColor];

[self addSubview:self.activity];

//视频出错提示

//    self.errorlable               = [[UILabel alloc]init];

//    self.errorlable.text          = @"亲,视频解析出错了!";

//    self.errorlable.textColor     = [UIColor whiteColor];

//    self.errorlable.textAlignment = NSTextAlignmentCenter;

//    self.errorlable.hidden        = YES;

//    [self addSubview:self.errorlable];

//返回按钮

self.backbutton = [UIButton buttonWithType:UIButtonTypeCustom];

[self.backbutton setImage:[UIImage imageNamed:@"public返回"] forState:UIControlStateNormal];

[self addSubview:self.backbutton];

//标题

self.titlelable = [[UILabel alloc]init];

self.titlelable.textColor = [UIColor whiteColor];

[self addSubview:self.titlelable];

}

- (void)layoutSubviews{

[super layoutSubviews];

self.leftplayerbutton.frame  = CGRectMake(10, self.frame.size.height - 40, 30, 30);

self.mintimelable.frame      = CGRectMake(CGRectGetMaxX(self.leftplayerbutton.frame), self.frame.size.height - 40, 60, 30);

self.slider.frame            = CGRectMake(CGRectGetMaxX(self.mintimelable.frame), self.frame.size.height - 35, self.frame.size.width - 2 *CGRectGetMaxX(self.mintimelable.frame), 20);

self.progressview.frame      = CGRectMake(self.slider.frame.origin.x + 6, self.slider.frame.origin.y, self.slider.frame.size.width - 12, 2);

self.progressview.center     = self.slider.center;

self.maxtimelable.frame      = CGRectMake(CGRectGetMaxX(self.slider.frame), self.frame.size.height - 40, 60, 30);

self.fullbutton.frame        = CGRectMake(CGRectGetMaxX(self.maxtimelable.frame), self.frame.size.height -40, 30, 30);

self.rightplayerbutton.frame = CGRectMake(self.frame.size.width - 60, self.frame.size.height - 100, 50, 50);

self.activity.frame          = CGRectMake(CGRectGetMidX(self.bounds) - 37*0.5, CGRectGetMidY(self.bounds)-37*0.5, 37, 37);

//self.errorlable.frame        = CGRectMake(self.frame.size.width/ 2 - 100, self.frame.size.height / 2 -10, 200, 20);

self.backbutton.frame        = CGRectMake(0, 0, 30, 30);

self.titlelable.frame        = CGRectMake(CGRectGetMaxX(self.backbutton.frame), CGRectGetMinY(self.backbutton.frame), self.frame.size.width - CGRectGetMaxX(self.backbutton.frame), 30);

}

- (void)dealloc{

}

上面这些是提示视图 和 手势视图    下面是主要 用avplayer  来播放   代码可以复制到你的工程里  把类改一下就行

#import <UIKit/UIKit.h>

@protocol XGAVPlayerViewdelegate <NSObject>

//全屏

- (void)XGAVPlayerViewfullScreen:(BOOL)fullscreen;

//返回

- (void)XGAVPlayerViewback;

@end

@interface XGAVPlayerView : UIView

//代理

@property (nonatomic ,weak)id<XGAVPlayerViewdelegate>delegate;

//本地和网络亦可

- (void)setUrl:(NSURL *)url andIsStartplay:(BOOL)isstartplay;

//

- (void)closeplay;

@end

#import "XGAVPlayerView.h"

#import "Reachability.h"

#import "XGGesTuresView.h"

#import <CoreTelephony/CTCall.h>

#import <AVFoundation/AVFoundation.h>

#import <CoreTelephony/CTCallCenter.h>

@interface XGAVPlayerView ()<UIAlertViewDelegate,UIGestureRecognizerDelegate>

//播放工具

@property (nonatomic ,strong)AVPlayer       * player;

//播放图层

@property (nonatomic ,strong)AVPlayerLayer  * playerlayer;

//播放资源对象

@property (nonatomic ,strong)AVPlayerItem   * playeritem;

//手势视图

@property (nonatomic ,strong)XGGesTuresView * gesturesview;

//错误lable

@property (nonatomic ,strong)UILabel        * errorlable;

//重连

@property (nonatomic ,strong)UIButton       * reconnectbutton;

//电话

@property (nonatomic ,strong)CTCallCenter   * telephone;

//播放地址

@property (nonatomic ,strong)NSURL          * playerurl;

//player时间观察者

@property (nonatomic ,strong)id               playTimeObserver;

//是否正在播放

@property (nonatomic ,assign)BOOL             isplaying;

//是否开始播放 可从外界控制

@property (nonatomic ,assign)BOOL             isstartplay;

//网络

@property (nonatomic ,assign)NetworkStatus    netstatus;

@end

@implementation XGAVPlayerView

//初始化

- (instancetype)initWithFrame:(CGRect)frame{

if (self = [super initWithFrame:frame]) {

self.backgroundColor = [UIColor blackColor];

[self creatAvPlayer];

[self creatUI];

[self addtap];

}

return self;

}

//播放管理

- (void)creatAvPlayer{

self.player = [[AVPlayer alloc]init];

self.playerlayer = [AVPlayerLayer playerLayerWithPlayer:self.player];

self.playerlayer.videoGravity = AVLayerVideoGravityResizeAspect;

[self.layer insertSublayer:self.playerlayer atIndex:0];//放到最底层

}

//视图

- (void)creatUI{

//错误

self.errorlable               = [[UILabel alloc]init];

self.errorlable.textColor     = [UIColor whiteColor];

self.errorlable.textAlignment = NSTextAlignmentCenter;

self.errorlable.hidden        = YES;

[self addSubview:self.errorlable];

//重连

self.reconnectbutton                 = [UIButton buttonWithType:UIButtonTypeCustom];

[self.reconnectbutton setTitle:@"重 连" forState:UIControlStateNormal];

self.reconnectbutton.backgroundColor = [UIColor greenColor];

self.reconnectbutton.hidden          = YES;

[self.reconnectbutton addTarget:self action:@selector(notreachableclick) forControlEvents:UIControlEventTouchUpInside];

[self addSubview:self.reconnectbutton];

//手势视图

self.gesturesview = [[XGGesTuresView alloc]init];

[self addSubview:self.gesturesview];

self.gesturesview.slider.value          = 0.0;//滑动条初始值

self.gesturesview.progressview.progress = 0.0;//缓冲条初始值

[self.gesturesview.leftplayerbutton  addTarget:self action:@selector(playclick) forControlEvents:UIControlEventTouchUpInside];

[self.gesturesview.fullbutton        addTarget:self action:@selector(fullclick:) forControlEvents:UIControlEventTouchUpInside];

[self.gesturesview.rightplayerbutton addTarget:self action:@selector(playclick) forControlEvents:UIControlEventTouchUpInside];

[self.gesturesview.backbutton        addTarget:self action:@selector(backclick) forControlEvents:UIControlEventTouchUpInside];

[self.gesturesview.slider            addTarget:self action:@selector(palyslidertouchdown:) forControlEvents:UIControlEventTouchDown];//按下

[self.gesturesview.slider            addTarget:self action:@selector(palysliderdrop:) forControlEvents:UIControlEventValueChanged];//拖动

[self.gesturesview.slider            addTarget:self action:@selector(palysliderdropfinish:) forControlEvents:UIControlEventTouchUpInside];//点击

}

//播放 暂停

- (void)playclick{

self.isplaying ? [self stopplay] :[self startplay];

}

//全屏

- (void)fullclick:(UIButton *)sender{

sender.selected = !sender.selected;

if (self.delegate && [self.delegate respondsToSelector:@selector(XGAVPlayerViewfullScreen:)]){

[self.delegate XGAVPlayerViewfullScreen:sender.selected];

}

}

//返回 如果反回到原始图(竖屏) 记得改变全屏按钮状态  如果返回到上一个控制器 则不需要改变全屏按钮状态 这里自定义

- (void)backclick{

[self stopplay];

if (self.delegate && [self.delegate respondsToSelector:@selector(XGAVPlayerViewback)]){

[self.delegate XGAVPlayerViewback];

}

}

//按下

- (void)palyslidertouchdown:(UISlider *)sender{

[self.player pause];

if (self.isplaying == YES) {

self.gesturesview.leftplayerbutton.selected  = YES;

self.gesturesview.rightplayerbutton.selected = YES;

}

[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(showgesturesview) object:nil];

}

//拖动

- (void)palysliderdrop:(UISlider *)sender{

CMTime changetime = CMTimeMakeWithSeconds(sender.value, 1.0);

self.gesturesview.mintimelable.text = [self convertTime:CMTimeGetSeconds(changetime)];

}

//拖动结束

- (void)palysliderdropfinish:(UISlider *)sender{

CMTime changetime = CMTimeMakeWithSeconds(sender.value, 1.0);

[self.playeritem seekToTime:changetime completionHandler:^(BOOL finished) {

self.isplaying ? [self startplay] : nil;

}] ;

}

//手势

- (void)addtap{

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showgesturesview)];

tap.delegate = self;

[self addGestureRecognizer:tap];

}

//手势方法

- (void)showgesturesview{

[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(showgesturesview) object:nil];

[UIView animateWithDuration:0.25 animations:^{

self.gesturesview.hidden      = !self.gesturesview.hidden;

[[UIApplication sharedApplication]setStatusBarHidden:self.gesturesview.hidden withAnimation:UIStatusBarAnimationFade];

} completion:nil];

}

//手势代理 用来解决uislider和tap 的手势冲突

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch{

if ([touch.view isKindOfClass:[UISlider class]]) {

return NO;

}

return YES;

}

//本地和网络亦可

- (void)setUrl:(NSURL *)url andIsStartplay:(BOOL)isstartplay{//进来优先检查网络

self.isstartplay = isstartplay;

self.playerurl   = url;

NetworkStatus firststatus = [self CheckNowNetWorkStatus];

switch (firststatus) {

case NotReachable:{//进来时没网络

[self notreachable];

}break;

case ReachableViaWiFi:{//进来wifi

[self reachableviawifi:url];

}break;

case ReachableViaWWAN:{//进来时没网络

UIAlertView * firstalert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"当前处于2g/3g/4g模式下,继续播放会产生流量!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

firstalert.tag = 1;

[firstalert show];

}break;

default:

break;

}

}

//无网络提示

- (void)notreachable{

[self stopplay];

self.errorlable.hidden = NO;

self.errorlable.text   = @"亲,没有网络!";

self.reconnectbutton.hidden = NO;

self.gesturesview.userInteractionEnabled = NO;

}

//刚进来时无网络状态 没有创建self.playeritem 和监听 所以不影响后面的

- (void)notreachableclick{

NetworkStatus reconnect = [self CheckNowNetWorkStatus];

switch (reconnect) {

case NotReachable:{//重连 无网络点击 不做任何反应

NSLog(@"无网络");

}break;

case ReachableViaWiFi:{//wifi

NSLog(@"wifi");

}

case ReachableViaWWAN:{//在流量状态重连 表示用户默认接受了流量状态下播放  wifi就不用说了

[self reachableviawifi:self.playerurl];

}break;

default:

break;

}

}

//wifi

- (void)reachableviawifi:(NSURL *)url{

self.errorlable.hidden = YES;

self.reconnectbutton.hidden = YES;

self.gesturesview.userInteractionEnabled = YES;

if ([url.absoluteString hasPrefix:@"http"] ||[url.absoluteString hasPrefix:@"https"]){//网络视频  添加网络监听

self.playeritem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:[url.absoluteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

[self addnetworkNotification];

}else{//本地

self.playeritem = [AVPlayerItem playerItemWithURL:url];

}

[self.player replaceCurrentItemWithPlayerItem:self.playeritem];

[self addNotification];

}

//网络监控

- (void)addnetworkNotification{

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(netchange:) name:kReachabilityChangedNotification object:nil];

}

//网络状态

- (void)netchange:(NSNotification *)noti{

Reachability * reach = [noti object];

if ([reach isKindOfClass:[Reachability class]]) {

NetworkStatus status = [reach currentReachabilityStatus];

[self updatenetworkstatus:status];

}

}

//根据网络 改变播放状态

- (void)updatenetworkstatus:(NetworkStatus)status{

switch (status) {

case NotReachable:{//无网络

[self notreachable];

}break;

case ReachableViaWiFi:{

self.errorlable.hidden = YES;

self.reconnectbutton.hidden = YES;

self.gesturesview.userInteractionEnabled = YES;

}break;

case ReachableViaWWAN:{//2g3g4g

[self stopplay];

UIAlertView * wwanalert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"当前处于2g/3g/4g模式下,继续播放会产生流量!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

wwanalert.tag = 2;

[wwanalert show];

}break;

default:

break;

}

}

//alert代理

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

switch (alertView.tag) {

case 1:{

if (buttonIndex != alertView.cancelButtonIndex) {

[self reachableviawifi:self.playerurl];

}

}break;

case 2:{

if (buttonIndex != alertView.cancelButtonIndex) {

[self startplay];

}

}break;

default:

break;

}

}

//通知

- (void)addNotification {

//kvo监听

[self.playeritem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];

// 监听loadedTimeRanges属性

[self.playeritem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];

// 播放完成通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];

// 前台通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];

// 后台通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];

[self monitoringPlayback:self.playeritem];

}

//键值观察

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {

if ([keyPath isEqualToString:@"status"]){//状态

AVPlayerStatus status = [[change objectForKey:@"new"] intValue];

if (status == AVPlayerStatusReadyToPlay) {

AVPlayerItem *item = (AVPlayerItem *)object;

self.gesturesview.slider.maximumValue = CMTimeGetSeconds(item.duration);// 获取视频长度 设置视频时间

self.gesturesview.maxtimelable.text   = [self convertTime:CMTimeGetSeconds(item.duration)];// 设置视频时间

self.isstartplay ? [self startplay]:[self stopplay];// 进来开始播放 进来暂停暂停

}else if (status == AVPlayerStatusFailed){//当地址不对 无网络时 会走此方法

NSLog(@"AVPlayerStatusFailed");

[self stopplay];

self.errorlable.hidden = NO;

self.errorlable.text   = @"亲,视频解析出错了!";

self.gesturesview.userInteractionEnabled = NO;

}else {

NSLog(@"AVPlayerStatusUnknown");

}

} else if ([keyPath isEqualToString:@"loadedTimeRanges"]){

NSTimeInterval timeInterval = [self availableDurationRanges]; // 缓冲时间

CGFloat totalDuration = CMTimeGetSeconds(self.playeritem.duration); // 总时间

[self.gesturesview.progressview setProgress:timeInterval / totalDuration animated:YES];//更新缓冲条

}

}

// 相对格林时间

- (NSString *)convertTime:(CGFloat)second {

NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

if (second / 3600 >= 1) {

[formatter setDateFormat:@"HH:mm:ss"];

} else {

[formatter setDateFormat:@"mm:ss"];

}

NSString *showTimeNew = [formatter stringFromDate:date];

return showTimeNew;

}

// 缓冲时间 计算

- (NSTimeInterval)availableDurationRanges {

NSArray *loadedTimeRanges = [self.playeritem loadedTimeRanges]; // 获取item的缓冲数组

CMTimeRange timeRange = [loadedTimeRanges.firstObject CMTimeRangeValue]; // 获取缓冲区域

float startSeconds = CMTimeGetSeconds(timeRange.start);// CMTimeRange 结构体 start duration 表示起始位置 和 持续时间

float durationSeconds = CMTimeGetSeconds(timeRange.duration);

NSTimeInterval result = startSeconds + durationSeconds; // 计算总缓冲时间 = start + duration

return result;

}

//播放完成通知

- (void)playbackFinished:(NSNotification *)notification {

self.playeritem = [notification object];

[self.playeritem seekToTime:kCMTimeZero]; // 跳转到初始

[self stopplay];//暂停

self.gesturesview.hidden = NO;

//[self startplay];//开始  无限循环

}

//进入前台

- (void)enterForeground:(NSNotification *)notification {

NSSet * currentsset = self.telephone.currentCalls;

if (currentsset == nil) {

if(!self.isplaying){//切刀后台最后一刻的状态

[self startplay];

}

}

}

//进入后台

- (void)enterBackground:(NSNotification *)notification {

[self stopplay];

}

// 观察播放进度 每秒执行1次, CMTime 为1秒

- (void)monitoringPlayback:(AVPlayerItem *)item {

__weak typeof(self)WeakSelf = self;

self.playTimeObserver = [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1.0) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {

//当前播放时间  秒

float currentPlayTime = (double)item.currentTime.value/ item.currentTime.timescale;

WeakSelf.gesturesview.slider.value      = currentPlayTime;

WeakSelf.gesturesview.mintimelable.text = [WeakSelf convertTime:currentPlayTime];

}];

}

//开始播放

- (void)startplay{

self.isplaying = YES;

[self.player play];

self.gesturesview.leftplayerbutton.selected  = NO;

self.gesturesview.rightplayerbutton.selected = NO;

[self performSelector:@selector(showgesturesview) withObject:nil afterDelay:5.0];

}

//暂停播放

- (void)stopplay{

self.isplaying = NO;

[self.player pause];

self.gesturesview.leftplayerbutton.selected  = YES;

self.gesturesview.rightplayerbutton.selected = YES;

[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(showgesturesview) object:nil];

}

//约束

- (void)layoutSubviews{

[super layoutSubviews];

self.playerlayer.frame     = self.bounds;

self.gesturesview.frame    = self.bounds;

self.errorlable.frame      = CGRectMake(self.frame.size.width/ 2 - 150, self.frame.size.height / 2 -20, 300, 20);

self.reconnectbutton.frame = CGRectMake(self.frame.size.width/ 2 - 30, CGRectGetMaxY(self.errorlable.frame) + 10, 60, 30);

}

//第一次进入页面判断网络状态使用

- (NetworkStatus)CheckNowNetWorkStatus{

NSArray *subviews = [[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];

NSNumber *dataNetworkItemView = nil;

for (id subview in subviews) {

if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {

dataNetworkItemView = subview;

break;

}

}

switch ([[dataNetworkItemView valueForKey:@"dataNetworkType"]integerValue]) {

case 0:NSLog(@"No wifi or cellular");

return NotReachable;

break;

case 1:NSLog(@"2G");

case 2:NSLog(@"3G");

case 3:NSLog(@"4G");

case 4:NSLog(@"LTE");

return ReachableViaWWAN;

break;

case 5:NSLog(@"Wifi");

return ReachableViaWiFi;

break;

default:

break;

}

return ReachableViaWiFi;

}

////手动释放

//- (void)closeplay{

//    [self.player pause];

//    [self.playeritem removeObserver:self forKeyPath:@"status"];

//    [self.playeritem removeObserver:self forKeyPath:@"loadedTimeRanges"];

//    [[NSNotificationCenter defaultCenter]removeObserver:self];

//    [self.player removeTimeObserver:self.playTimeObserver];

//    self.playTimeObserver = nil;

//    [self.player replaceCurrentItemWithPlayerItem:nil];

//

//}

//自动释放

-(void)dealloc{

[[NSNotificationCenter defaultCenter]removeObserver:self];

[self.player removeTimeObserver:self.playTimeObserver];

self.playTimeObserver = nil;

[self.player replaceCurrentItemWithPlayerItem:nil];

[self.playeritem removeObserver:self forKeyPath:@"status"];

[self.playeritem removeObserver:self forKeyPath:@"loadedTimeRanges"];

}

网络监听类 Reachability.h  网上很多 苹果官网也有 可以自己去下   如果还是不明白 可以吧联系方式留下  有空我会发到你的邮箱

时间: 2024-10-17 02:14:12

ios avplayer 视频播放器的相关文章

ios媒体视频播放器应用项目

源码WSY_XMHelper,基于ReactiveCocoa和MVVM架构的流媒体视频播放器应用,此项目为一个完整项目.基于MVVM架构, 集成流媒体视频下载及播放,支持下拉刷新,上拉加载等.如果你想学习MVVM,此项目为一个很好的例子. 项目源码下载:http://code.662p.com/view/9891.html<ignore_js_op> <ignore_js_op> 详细说明:http://ios.662p.com/thread-2344-1-1.html

iOS媒体视频播放器应用源码

源码WSY_XMHelper,基于ReactiveCocoa和MVVM架构的流媒体视频播放器应用,此项目为一个完整项目.基于MVVM架构, 集成流媒体视频下载及播放,支持下拉刷新,上拉加载等.如果你想学习MVVM,此项目为一个很好的例子. 源码下载: http://code.662p.com/view/9891.html 2015-1-7 15:12 上传 详细说明:http://ios.662p.com/thread-2344-1-1.html

iOS: FFmpeg视频播放器

现在视频直播非常的火,所以在视频直播开发中,使用的对视频进行解码的框架显得尤为重要了,其实,这种框架蛮多的,这次主要介绍一下FFmpeg视频播放器的集成和使用 原址:http://bbs.520it.com/forum.php?mod=viewthread&tid=707&page=1&extra=#pid3821 一 本播放器原理: 通过ffmpeg对视频进行解码,解码出每一帧图片,然后根据一定时间播放每一帧图 二 如何集成 ffmpeg 下载脚本 ffmpeg脚本 根据上面链接

ios系统视频播放器MPMoviePlayerController应用遇到的坑

最近在做视频播放时应用系统MPMoviePlayerController播放器播放视频,发现点击快进快退会出现黑屏现象,并且点击完成按钮也不会返回,代码以及界面如下所示: NSURL *url=[self getNetworkUrl]; _moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:url]; _moviePlayer.view.frame=CGRectMake(0, 0, kScreenWidth, kScree

ios开发视频播放后台下载功能实现 :1,ios播放视频 ,包含基于AVPlayer播放器,2,实现下载,iOS后台下载(多任务同时下载,单任务下载,下载进度,下载百分比,文件大小,下载状态)(真机调试功能正常)

ABBPlayerKit ios开发视频播放后台下载功能实现 : 代码下载地址:https://github.com/niexiaobo/ABBPlayerKit github资料学习和下载地址:https://github.com/niexiaobo/ 实现功能 :播放视频 ,视频后台下载 (真机调试功能正常) 1.使用ZFPlayer播放视频(可以在线和本地播放,基于AVPlayer,调节音量和屏幕亮度) 2.使用 WHCNetWorkKit 实现下载,后台下载(多任务同时下载,单任务下载,

iOS - AVPlayer 音视频播放

iOS - AVPlayer 音视频播放 本文目录 前言 1.本地/网络音视频播放 2.本地/网络音视频播放设置 3.AVPlayerViewControllerDelegate 画中画协议方法 回到顶部 前言 NS_CLASS_AVAILABLE(10_7, 4_0) @interface AVPlayer : NSObject @available(iOS 4.0, *) public class AVPlayer : NSObject NS_CLASS_AVAILABLE_IOS(8_0)

IOS视频播放器VKVideoPlayer

VKVideoPlayer 是一个在 Viki iOS 应用里使用的视频播放器. 主要特性: 完全可定制的 UI 任何大小乃至全屏 支持字幕显示 可定制的字幕显示风格 支持 HTTP 直播流 支持屏幕方向调整 Bulletproof event machine to easily integrate features like video ads Lots of delegate callbacks for your own logging requirements VKVideoPlayer是

cocos2dx ios 视频播放器 2.x到3.x版本都可以使用

在cocos2dx版本中使用视频播放器的话 需要以下步骤 1.在写一个.mm的文件 我这里的mm叫IOSPlayVedio这个 头文件定义这个 static void playOnLineVideo4IOS(char *pszVideoUrl); .mm里面写 void IOSPlayVedio::playOnLineVideo4IOS(char *pszVideoUrl) { NSString * strVideo = [NSString stringWithUTF8String:pszVid

ios 视频播放器MPMoviePlayerController

这个东西和之前的音频播放差不多, 也是先需要导入系统框架MediaPlayer.framework 才能使用到MPMoviePlayerController 的文件中导入相应的头文件 初始化:这里就有些不一样了MPMoviePlayerController是可以通过远程url初始化的, 例如: MPMoviePlayerController *moviePlayer = [ [ MPMoviePlayerController alloc]initWithContentURL:[NSURL url