AVPlayer demo

本文介绍了一个基于 iOS 的 AVPlayer 实现的视频播放器,详细讲解了如何利用 AVPlayer 播放视频、添加播放控制、进度条交互、手势监听等功能,并展示了如何处理视频播放状态变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. //  
  2. //  SMAVPlayerViewController.m  
  3. //  AVPlayerDemo  
  4. //  
  5. //  Created by Yx on 15/11/29.  
  6. //  Copyright © 2015年 WuhanBttenMobileTechnologyCo.,Ltd. All rights reserved.  
  7. //  
  8.   
  9. #import "SMAVPlayerViewController.h"  
  10. #import <AVFoundation/AVFoundation.h>  
  11. #import "SMSliderBar.h"  
  12. #import "MBMessageTip.h"  
  13. #import "VedioModel.h"  
  14. #import "VedioHistory.h"  
  15.   
  16. #define ScreenHeight [[UIScreen mainScreen] bounds].size.height  
  17. #define ScreenWidth [[UIScreen mainScreen] bounds].size.width  
  18.   
  19. @interface SMAVPlayerViewController ()<SMSliderDelegate>  
  20. @property (weak, nonatomic) IBOutlet UIView *viewHead;              //显示返回按钮View  
  21. @property (weak, nonatomic) IBOutlet UIView *viewLogin;             //加载view  
  22. @property (weak, nonatomic) IBOutlet UIImageView *imageViewLogin;   //加载image  
  23. @property (weak, nonatomic) IBOutlet UIView *viewAvPlayer;          //播放视图  
  24. @property (weak, nonatomic) IBOutlet SMSliderBar *slider;           //进度条  
  25. @property (weak, nonatomic) IBOutlet UIView *viewBottom;            //底部控制view  
  26. @property (weak, nonatomic) IBOutlet UIButton *btnPause;            //暂停播放按钮  
  27. @property (weak, nonatomic) IBOutlet UIButton *btnNetx;             //下一个按钮  
  28. @property (weak, nonatomic) IBOutlet UILabel *labelTimeNow;         //当前时间label  
  29. @property (weak, nonatomic) IBOutlet UILabel *labelTimeTotal;       //总时间label  
  30. @property (strongnonatomicAVPlayer *player;                     //播放器对象  
  31. @property (strongnonatomicid timeObserver;                      //视频播放时间观察者  
  32. @property (assign, nonatomicfloat totalTime;                      //视频总时长  
  33. @property (assign, nonatomicBOOL isHasMovie;                      //是否进行过移动  
  34. @property (assign, nonatomicBOOL isBottomViewHide;                //底部的view是否隐藏  
  35. @property (assign, nonatomic) NSInteger subscript;                  //数组下标,记录当前播放视频  
  36. @property (assign, nonatomic) NSInteger currentTime;                //当前视频播放时间位置  
  37. @end  
  38.   
  39. @implementation SMAVPlayerViewController  
  40. @synthesize subscript;  
  41.   
  42. - (void)viewDidLoad {  
  43.     [super viewDidLoad];  
  44.     self.slider.type = SMSliderTypeHoz;  
  45.     self.slider.progressBgColor = [UIColor whiteColor];  
  46.     self.slider.isAllowDrag = YES;  
  47.     self.slider.delegate=self;  
  48.     subscript = 0;  
  49.     self.currentTime = 0;  
  50.     [self prohibitOperation];  
  51.     [self setMediaPlayer];  
  52.     [self addPlayerClick];//双击,单击事件  
  53.     [self addProgressObserver];//进度监听  
  54.     [self addNotification];//广播监听播放状态  
  55.     [self setupObservers];//监听应用状态  
  56.     self.viewLogin.layer.cornerRadius = 8;  
  57.     self.imageViewLogin.layer.masksToBounds = YES;  
  58.     self.imageViewLogin.layer.cornerRadius = 34/2;  
  59.     splashTimer = [NSTimer scheduledTimerWithTimeInterval:1  target:self selector:@selector(roteImageView) userInfo:nil repeats:YES];  
  60.     [[NSRunLoop currentRunLoop] addTimer:splashTimer forMode:NSRunLoopCommonModes];  
  61. }  
  62.   
  63. - (void)viewDidAppear:(BOOL)animated  
  64. {  
  65.     [super viewDidAppear:animated];  
  66.     [[UIApplication sharedApplication]setStatusBarHidden:YES];  
  67.     //接受远程控制事件  
  68.     [[UIApplication sharedApplication]beginReceivingRemoteControlEvents];  
  69.     [self becomeFirstResponder];  
  70. }  
  71.   
  72. - (void)viewDidDisappear:(BOOL)animated  
  73. {  
  74.     [super viewDidDisappear:animated];  
  75.     [[UIApplication sharedApplication] setStatusBarHidden:NO];  
  76.     [[UIApplication sharedApplication] endReceivingRemoteControlEvents];  
  77.     [self resignFirstResponder];  
  78.     [splashTimer invalidate];  
  79. }  
  80.   
  81. - (void)setMediaPlayer{  
  82.     //创建播放器层  
  83.     AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];  
  84.     playerLayer.frame = CGRectMake(00, ScreenHeight ,ScreenWidth );  
  85.     [self.viewAvPlayer.layer addSublayer:playerLayer];  
  86.     [self.player seekToTime:CMTimeMakeWithSeconds(self.startTime1000)];//设置播放位置1000 为帧率  
  87.     [_player play];  
  88. }  
  89.   
  90.   
  91. #pragma mark - set/get  
  92. - (AVPlayer *)player{  
  93.     if (!_player) {  
  94.         AVPlayerItem *playerItem = [self getPlayItem:subscript];  
  95.         [self addObserverToPlayerItem:playerItem];  
  96.         _player = [AVPlayer playerWithPlayerItem:playerItem];  
  97.     }  
  98.     return _player;  
  99. }  
  100.   
  101. - (AVPlayerItem *)getPlayItem:(NSUInteger)videoIndex{  
  102.     /*播放本地视频 
  103.     NSString *urlStr=[[NSBundle mainBundle] pathForResource:@"testav.mp4" ofType:nil]; 
  104.     NSURL *url=[NSURL fileURLWithPath:urlStr]; 
  105.     AVPlayerItem *playerItem=[AVPlayerItem playerItemWithURL:url]; 
  106.     return playerItem;*/  
  107.     //NSString *urlStr= @"http://7xoour.com2.z0.glb.qiniucdn.com/9605401000";  
  108.     _currentTime = 0;  
  109.     [self savePayHistory];  
  110.     VedioModel *vedioModel = _arrVedio[videoIndex];  
  111.     NSString *urlStr =[vedioModel.strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  112.     NSURL *url=[NSURL URLWithString:urlStr];  
  113.     /*获取总帧数与帧率 
  114.      NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] 
  115.      forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; 
  116.      AVURLAsset *myAsset = [[AVURLAsset alloc] initWithURL:url options:opts]; 
  117.      CMTimeValue  value = myAsset.duration.value;//总帧数 
  118.      CMTimeScale  timeScale =   myAsset.duration.timescale; //timescale为帧率  fps 
  119.      */  
  120.     AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];  
  121.     return playerItem;  
  122. }  
  123.   
  124. #pragma mark - 通知  
  125. //给AVPlayerItem添加播放完成通知  
  126. - (void)addNotification{  
  127.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];  
  128. }  
  129.   
  130. // 播放完成通知  
  131. - (void)playbackFinished:(NSNotification *)notification{  
  132.     NSLog(@"视频播放完成.");  
  133.     [self prohibitOperation];  
  134.     [self savePayHistory];  
  135.     [self nextClick:nil];  
  136. }  
  137.   
  138. //注册通知  
  139. - (void)setupObservers  
  140. {  
  141.     NSNotificationCenter *notification = [NSNotificationCenter defaultCenter];  
  142.     [notification addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationWillEnterForegroundNotification object:[UIApplication sharedApplication]];  
  143.     [notification addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]];  
  144. }  
  145.   
  146. - (void)applicationDidBecomeActive:(NSNotification *)notification  
  147. {  
  148.     if (self.player.rate == 0) {  
  149.         [self.player play];  
  150.         [self.btnPause setTitle:@"暂停" forState:UIControlStateNormal];  
  151.         [self.btnPause setBackgroundImage:[UIImage imageNamed:@"play_stop.png"] forState:UIControlStateNormal];  
  152.     }  
  153. }  
  154.   
  155. - (void)applicationDidEnterBackground:(NSNotification *)notification  
  156. {  
  157.     if (self.player.rate == 1){  
  158.         [self.player pause];  
  159.         [self.btnPause setTitle:@"播放" forState:UIControlStateNormal];  
  160.         [self.btnPause setBackgroundImage:[UIImage imageNamed:@"play_start.png"] forState:UIControlStateNormal];  
  161.     }  
  162. }  
  163.   
  164. - (void)removeNotification{  
  165.     [[NSNotificationCenter defaultCenter] removeObserver:self];  
  166. }  
  167.   
  168. #pragma mark - KVO  
  169. - (void)addProgressObserver{  
  170.     AVPlayerItem *playerItem = self.player.currentItem;  
  171.     //这里设置每秒执行一次  
  172.     __weak __typeof(self) weakself = self;  
  173.     self.timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMake(1.01.0) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {  
  174.         float current = CMTimeGetSeconds(time);  
  175.         float total = CMTimeGetSeconds([playerItem duration]);  
  176.         NSLog(@"当前已经播放%f",current);  
  177.         weakself.currentTime = current;  
  178.         if (current) {  
  179.             [weakself setTime:current withTotal:total];  
  180.         }  
  181.     }];  
  182. }  
  183.   
  184. /** 
  185.  *  给AVPlayerItem添加监控 
  186.  *  @param playerItem AVPlayerItem对象 
  187.  */  
  188. - (void)addObserverToPlayerItem:(AVPlayerItem *)playerItem{  
  189.     //监控状态属性,注意AVPlayer也有一个status属性,通过监控它的status也可以获得播放状态  
  190.     [playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];  
  191.     //监控网络加载情况属性  
  192.     [playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];  
  193.     //监听播放的区域缓存是否为空  
  194.     [playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];  
  195.     //缓存可以播放的时候调用  
  196.     [playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];  
  197. }  
  198.   
  199. - (void)removeObserverFromPlayerItem:(AVPlayerItem *)playerItem{  
  200.     [playerItem removeObserver:self forKeyPath:@"status"];  
  201.     [playerItem removeObserver:self forKeyPath:@"loadedTimeRanges"];  
  202.     [playerItem removeObserver:self forKeyPath:@"playbackBufferEmpty"];  
  203.     [playerItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];  
  204. }  
  205. /** 
  206.  *  通过KVO监控播放器状态 
  207.  *  @param keyPath 监控属性 
  208.  *  @param object  监视器 
  209.  *  @param change  状态改变 
  210.  *  @param context 上下文 
  211.  */  
  212. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(voidvoid *)context{  
  213.     AVPlayerItem *playerItem = object;  
  214.     if ([keyPath isEqualToString:@"status"]) {  
  215.         AVPlayerStatus status= [[change objectForKey:@"new"] intValue];  
  216.         if(status == AVPlayerStatusReadyToPlay){  
  217.             self.totalTime = CMTimeGetSeconds(playerItem.duration);  
  218.             NSLog(@"开始播放,视频总长度:%.2f",CMTimeGetSeconds(playerItem.duration));  
  219.             [self.btnPause setTitle:@"暂停" forState:UIControlStateNormal];  
  220.              [self.btnPause setBackgroundImage:[UIImage imageNamed:@"play_stop.png"] forState:UIControlStateNormal];  
  221.             [_player play];  
  222.             [self.viewLogin setHidden:YES];  
  223.             [self clearProhibitOperation];  
  224.         }else if(status == AVPlayerStatusUnknown){  
  225.             NSLog(@"%@",@"AVPlayerStatusUnknown");  
  226.         }else if (status == AVPlayerStatusFailed){  
  227.             NSLog(@"%@",@"AVPlayerStatusFailed");  
  228.         }  
  229.     }else if([keyPath isEqualToString:@"loadedTimeRanges"]){  
  230.         NSArray *array = playerItem.loadedTimeRanges;  
  231.         CMTimeRange timeRange = [array.firstObject CMTimeRangeValue];//本次缓冲时间范围  
  232.         float startSeconds = CMTimeGetSeconds(timeRange.start);  
  233.         float durationSeconds = CMTimeGetSeconds(timeRange.duration);  
  234.         NSTimeInterval totalBuffer = startSeconds + durationSeconds;//缓冲总长度  
  235.         if (self.currentTime < (startSeconds + durationSeconds + 8)) {  
  236.             self.viewLogin.hidden  = YES;  
  237.             if ([self.btnPause.titleLabel.text isEqualToString:@"暂停"]) {  
  238.                 [_player play];  
  239.             }  
  240.         }else{  
  241.             self.viewLogin.hidden = NO;  
  242.         }  
  243.         self.slider.bufferValue = totalBuffer/self.totalTime;  
  244.         NSLog(@"缓冲:%.2f",totalBuffer);  
  245.     }else if ([keyPath isEqualToString:@"playbackBufferEmpty"]){  
  246.         NSLog(@"playbackBufferEmpty");  
  247.         [self.viewLogin setHidden:YES];  
  248.     }else if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]){  
  249.         [self.viewLogin setHidden:NO];  
  250.         NSLog(@"playbackLikelyToKeepUp");  
  251.     }  
  252. }  
  253.   
  254. #pragma mark - 手势监听  
  255. - (void)addPlayerClick{  
  256.     //单机手势监听  
  257.     UITapGestureRecognizer * tapGes=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playerSingleClick:)];  
  258.     tapGes.numberOfTapsRequired=1;  
  259.     [self.viewAvPlayer addGestureRecognizer:tapGes];  
  260.     /* 
  261.     //双击手势监听 
  262.     UITapGestureRecognizer * tapGesDouble=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playerDoubleTap:)]; 
  263.     tapGesDouble.numberOfTapsRequired=2; 
  264.     [self.viewAvPlayer addGestureRecognizer:tapGesDouble]; 
  265.     //双击手势确定监测失败才会触发单击手势的相应操作 
  266.     [tapGes requireGestureRecognizerToFail:tapGesDouble];*/  
  267. }  
  268.   
  269. //显示或隐藏控制view  
  270. - (void)playerSingleClick:(UITapGestureRecognizer*)recognizer{  
  271.     if (self.isBottomViewHide) {  
  272.         //显示  
  273.         [UIView animateWithDuration:0.3 animations:^{  
  274.             [self.viewBottom setAlpha:1];  
  275.             [self.viewHead setAlpha:1];  
  276.         }];  
  277.     }else{  
  278.         //隐藏  
  279.         [UIView animateWithDuration:0.3 animations:^{  
  280.             [self.viewBottom setAlpha:0.0];  
  281.             [self.viewHead setAlpha:0.0];  
  282.         }];  
  283.     }  
  284.     self.isBottomViewHide=!self.isBottomViewHide;  
  285. }  
  286.   
  287. //改变播放模式  
  288. - (void)playerDoubleTap:(UITapGestureRecognizer*)recognizer{  
  289.     AVPlayerLayer *playerLayer=[AVPlayerLayer playerLayerWithPlayer:self.player];  
  290.     if ([playerLayer.videoGravity isEqualToString:AVLayerVideoGravityResizeAspect]) {  
  291.         playerLayer.videoGravity=AVLayerVideoGravityResizeAspectFill;  
  292.     }else if ([playerLayer.videoGravity isEqualToString:AVLayerVideoGravityResizeAspectFill]){  
  293.         playerLayer.videoGravity=AVLayerVideoGravityResize;  
  294.     }else if ([playerLayer.videoGravity isEqualToString:AVLayerVideoGravityResize]){  
  295.         playerLayer.videoGravity=AVLayerVideoGravityResizeAspect;  
  296.     }  
  297. }  
  298.   
  299. #pragma mark - smSliderDelegate  
  300. - (void)SMSliderBar:(UIView *)slider valueChanged:(float)value{  
  301.     self.isHasMovie = YES;  
  302. }  
  303.   
  304. - (void)SMSliderBarBeginTouch:(UIView *)slider{  
  305.     [_player pause];  
  306.     self.isHasMovie = NO;  
  307. }  
  308.   
  309. - (void)SMSliderBarEndTouch:(UIView *)slider{  
  310.     if (self.isHasMovie) {  
  311.         [_player seekToTime:CMTimeMakeWithSeconds(self.totalTime*self.slider.value, _player.currentItem.duration.timescale)completionHandler:^(BOOL finished) {  
  312.             if (finished) {  
  313.                 [_player play];  
  314.             }  
  315.         }];  
  316.     }  
  317. }  
  318.   
  319.   
  320. #pragma mark - IBAction  
  321.   
  322. - (IBAction)pauseClick:(id)sender {  
  323.     if (_player.rate == 0) {  
  324.         [_player play];  
  325.         [self.btnPause setTitle:@"暂停" forState:UIControlStateNormal];  
  326.         [self.btnPause setBackgroundImage:[UIImage imageNamed:@"play_stop.png"] forState:UIControlStateNormal];  
  327.     }else{  
  328.         [_player pause];  
  329.         [self.btnPause setTitle:@"播放" forState:UIControlStateNormal];  
  330.         [self.btnPause setBackgroundImage:[UIImage imageNamed:@"play_start.png"] forState:UIControlStateNormal];  
  331.     }  
  332. }  
  333.   
  334. - (IBAction)nextClick:(id)sender {  
  335.     ++subscript;  
  336.     self.labelTimeNow.text = @"00:00:00";  
  337.     self.labelTimeTotal.text = @"00:00:00";  
  338.     self.slider.value = 0;  
  339.     if (subscript < self.arrVedio.count) {  
  340.         [self.player seekToTime:CMTimeMakeWithSeconds(0, _player.currentItem.duration.timescale)];  
  341.         [self removeNotification];  
  342.         [self removeObserverFromPlayerItem:self.player.currentItem];  
  343.         [self.player removeTimeObserver:self.timeObserver];  
  344.          [_player replaceCurrentItemWithPlayerItem:[self getPlayItem:subscript]];  
  345.         [self addObserverToPlayerItem:self.player.currentItem];  
  346.         [self addNotification];  
  347.         [self addProgressObserver];  
  348.         if (self.player.rate == 0 ) {  
  349.             [self.player play];  
  350.         }  
  351.     }else{  
  352.         --subscript;  
  353.         /* 
  354.          [self.player.currentItem cancelPendingSeeks]; 
  355.          [self.player.currentItem.asset cancelLoading]; 
  356.          */  
  357.         [self.btnPause setTitle:@"播放" forState:UIControlStateNormal];  
  358.         [self.btnPause setBackgroundImage:[UIImage imageNamed:@"play_start.png"] forState:UIControlStateNormal];  
  359.         self.labelTimeTotal.text = @"00:00:00";  
  360.         self.labelTimeNow.text = @"00:00:00";  
  361.         [MBMessageTip messageWithTip:self.view withMessage:@"没有更多了" ];  
  362.     }  
  363. }  
  364.   
  365. - (IBAction)backAction:(id)sender {  
  366.     [self savePayHistory];  
  367.     [self.player pause];  
  368.     [self dismissViewControllerAnimated:YES completion:nil];  
  369. }  
  370.   
  371. #pragma mark - interface rotation  
  372.   
  373. //横屏  
  374. - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{  
  375.       
  376.     return YES;  
  377. }  
  378.   
  379. - (UIInterfaceOrientationMask)supportedInterfaceOrientations  
  380. {  
  381.     return UIInterfaceOrientationMaskLandscapeRight;  
  382. }  
  383.   
  384. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation  
  385. {  
  386.     NSString *frameString = NSStringFromCGRect(self.viewAvPlayer.frame);  
  387.       
  388.     NSLog(@"视频窗口的frame:%@",frameString);  
  389. }  
  390.   
  391. #pragma mark - 私有方法  
  392. //设置播放时长  
  393. - (void)setTime:(float)current withTotal:(float)total{  
  394.     self.slider.value = current/total;  
  395.     self.labelTimeNow.text = [self displayTime:(int)current];  
  396.     self.labelTimeTotal.text = [self displayTime:(int)total];  
  397. }  
  398.   
  399. - (NSString*)displayTime:(int)timeInterval{  
  400.     NSString * time = @"";  
  401.     int seconds = timeInterval % 60;  
  402.     int minutes = (timeInterval / 60) % 60;  
  403.     int hours = timeInterval / 3600;  
  404.     NSString * secondsStr=seconds<10?[NSString stringWithFormat:@"%@%d",@"0",seconds]:[NSString stringWithFormat:@"%d",seconds];  
  405.     NSString * minutesStr=minutes<10?[NSString stringWithFormat:@"%@%d",@"0",minutes]:[NSString stringWithFormat:@"%d",minutes];  
  406.     NSString * hoursStr=hours<10?[NSString stringWithFormat:@"%@%d",@"0",hours]:[NSString stringWithFormat:@"%d",hours];  
  407.     time = [NSString stringWithFormat:@"%@%@%@%@%@",hoursStr,@":",minutesStr,@":",secondsStr];  
  408.     return time;  
  409. }  
  410.   
  411. //视频加载指示条  
  412. - (void)roteImageView{  
  413.     CABasicAnimation* rotationAnimation;  
  414.     rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];  
  415.     rotationAnimation.toValue = [NSNumber numberWithFloatM_PI * 2.0 ];  
  416.     rotationAnimation.cumulative = YES;  
  417.     rotationAnimation.repeatCount = 1;  
  418.     rotationAnimation.duration = 1;  
  419.     [self.imageViewLogin.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];  
  420. }  
  421.   
  422. //保存播放历史  
  423. - (void)savePayHistory{  
  424.     NSDate *currentDate = [NSDate date];//获取当前时间,日期  
  425.     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];  
  426.     [dateFormatter setDateFormat:@"YYYY-MM-dd"];  
  427.     NSString *dateString = [dateFormatter stringFromDate:currentDate];  
  428.     VedioModel *vedioModel = _arrVedio[subscript];  
  429.     VedioHistory *vedioHistory = [[VedioHistory alloc] init];  
  430.     [vedioHistory insertTitle:vedioModel.strTitle createTime:dateString userId:[NSNumber numberWithInt:[vedioModel.strUserID intValue]] videoType:[NSNumber numberWithInt:vedioModel.vedioType playTime:[NSNumber numberWithInteger:self.currentTime] videoUrl:vedioModel.strURL picUrl:vedioModel.strImage];  
  431. }  
  432.   
  433. //视频未播放时禁止点击  
  434. - (void)prohibitOperation{  
  435.     self.btnNetx.enabled = NO;  
  436.     self.btnPause.enabled = NO;  
  437.     self.slider.isAllowDrag = NO;  
  438. }  
  439.   
  440. //视频播放时取消禁止点击  
  441. - (void)clearProhibitOperation{  
  442.     self.btnNetx.enabled = YES;  
  443.     self.btnPause.enabled = YES;  
  444.     self.slider.isAllowDrag = YES;  
  445. }  
  446.   
  447. - (void)dealloc{  
  448.     [[NSNotificationCenter defaultCenter] removeObserver:self];  
  449.     [self removeObserverFromPlayerItem:self.player.currentItem];  
  450.     [self.player removeTimeObserver:self.timeObserver];  
  451. }  
  452.   
  453. - (void)didReceiveMemoryWarning {  
  454.     [super didReceiveMemoryWarning];  
  455. }  
  456.   
  457. @end 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值