YIem`s Blog -心比天高命比纸薄-链接找不到的请在站内搜索内容!

iOS-多媒体-视频播放 - 边下边播-








//

// ViewController.m
// UI24_多媒体_视频
//
// Created by YIem on 16/3/14.
// Copyright © 2016年 YIem. All rights reserved.
//

import "ViewController.h"

// 包含视频播放库文件

import <AVFoundation/AVFoundation.h>

@interface ViewController ()
// 设置属性 - (方便操作)
// 视频信息
@property (nonatomic, retain) AVPlayer *player;
// 显示窗口
@property (nonatomic, retain) AVPlayerLayer *playerLayer;
// 视频信息
@property (nonatomic, retain) AVPlayerItem *playerItem;
// 滑动条
@property (nonatomic, retain) UISlider *progerssSlider;
// UIView
@property (nonatomic, retain) UIView *boomV;
// 判断(视频按钮(如播放进度的))影藏/显示
@property (nonatomic, assign) BOOL isTap;
@end

@implementation ViewController

warning - UIView

self.boomV = [[UIView alloc] initWithFrame:CGRectMake(0, 250, [UIScreen mainScreen].bounds.size.width, 50)];
// View 的背景颜色
self.boomV.backgroundColor = [UIColor blackColor];
[self.view addSubview:_boomV];

warning - 视频 - 滑动条

self.progerssSlider = [[UISlider alloc] initWithFrame:CGRectMake(5, 10, [UIScreen mainScreen].bounds.size.width - 5 * 2, 30)];
// 添加滑动条到 View上
[self.boomV addSubview:_progerssSlider];
// 添加方法
[self.progerssSlider addTarget:self action:@selector(progerssSliderAction:) forControlEvents:UIControlEventValueChanged];

warning - 手势

UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
// 添加轻拍手势
[self.view addGestureRecognizer:tapGR];

pragma - 获取视频- 播放视频

[self createPlayer];

pragma - 播放

[self.player play];

pragma - 音量设置

self.player.volume = 0;

pragma - 暂停

// [self.player pause];

pragma - 调用 - 监听(状态)

[self addNotificationCenters];

pragma - 调用 - 视频时间

[self addprogerssObserver];

}

pragma - 轻拍手势 实现

pragma - 滑动条 实现

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

// 获取视频的总时长
CGFloat duration = CMTimeGetSeconds(self.playerItem.duration);
// 当前播放的时间
CGFloat currentTime = sender.value * duration;
// 拖拽时间前进
CMTime dragedCMTime = CMTimeMake(currentTime, 1);
// 设置播放时间 - 拖拽
[self.player seekToTime:dragedCMTime completionHandler:^(BOOL finished) {
    
}];

}

warning - 视频 时间

}

warning - 监听

pragma - 实现监听是否完成播放

pragma - 实现监听屏幕旋转

warning - 获取数据 - 播放视频

@end

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »