赞
踩
4、封装独立的弹框视图,可加网络判断来是否继续播放
github地址:https://github.com/Janko0/JKAVPlayer
播放器使用
//
// ViewController.m
// JKPlayer
//
// Created by 杨可 on 2016/12/23.
// Copyright © 2016年 Janko. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<JKPlayerViewDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *playBtn = [[UIButton alloc] init];
playBtn.frame = CGRectMake(100, 400, 100, 100);
[playBtn setTitle:@"播放" forState:UIControlStateNormal];
[playBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self.view addSubview:playBtn];
[playBtn addTarget:self action:@selector(playVideo) forControlEvents:UIControlEventTouchUpInside];
// [[TTPlayerViewMananger playerViewMananger] replaceSuperView:self.view];
// [[TTPlayerViewMananger playerViewMananger] setTopView:self.topView playerDeleagte:self];
}
- (void)playVideo {
[[JKPlayerViewMananger playerViewMananger] removePlayer];
if ([JKPlayerViewMananger playerViewMananger].playerView == nil) {
[[JKPlayerViewMananger playerViewMananger] setPlayerViewFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * (9 / 16.0)) topView:nil selfSuperView:self.view delegate:self];
}
[JKPlayerViewMananger playerViewMananger].playerView.showBackBtn = YES;
if ([JKPlayerViewMananger playerViewMananger].playerView.indicatorView.isAnimating) {
[[JKPlayerViewMananger playerViewMananger].playerView.indicatorView startAnimation];
}
//http://baobab.cdn.wandoujia.com/14468618701471.mp4
[[JKPlayerViewMananger playerViewMananger] playWithVideoUrlString:@"http://test.bjrenrentong.com/hls/host1-d5fbb6440bea7f29c7edf23f6bc7b89c.mov/m3u8"];
}
- (CGRect)getHalfScreenFrame
{
return CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * (9 / 16.0));
}
- (void)loadVideoFinish:(BOOL)isLoadSuccess
{
if (isLoadSuccess)
{
[[JKPlayerViewMananger playerViewMananger] playVideo];
}
else
{
[SVProgressHUD showErrorWithStatus:@"视频出错啦"];
}
}
@end
播放器管理类实现
//
// JKPlayerViewMananger.m
// JKPlayer
//
// Created by Janko on 16/6/28.
// Copyright © 2016年 Janko. All rights reserved.
//
#import "JKPlayerViewMananger.h"
@interface JKPlayerViewMananger ()
@end
@implementation JKPlayerViewMananger
static JKPlayerViewMananger *mananger;
static JKPlayerView *playerView;
+ (instancetype)playerViewMananger {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mananger = [[JKPlayerViewMananger alloc] init];
});
return mananger;
}
- (instancetype)setPlayerViewFrame:(CGRect)frame topView:(UIView *)topView selfSuperView:(UIView *)selfSuperView delegate:(id<JKPlayerViewDelegate>)delegate {
self.playerView = [[JKPlayerView alloc] initWithFrame:frame topView:topView selfSuperView:selfSuperView delegate:delegate];
if (self.playerView.isFullScreen) {
[self.playerView changeToHalfScreen];
}
return self;
}
- (void)playWithVideoUrlString:(NSString *)videoUrlString selfSuperView:(UIView *)selfSuperView {
[self.playerView playWithVideoUrlString:videoUrlString selfSuperView:selfSuperView];
}
- (void)seJKopView:(UIView *)topView playerDeleagte:(id<JKPlayerViewDelegate>) delegate {
[self.playerView seJKopView:topView playerDeleagte:delegate];
}
#pragma mark - 外部接口
- (void)changeToHalfScreen {
[self.playerView changeToHalfScreen];
}
- (void)playWithVideoUrlString:(NSString *)videoUrlString {
[self.playerView playWithVideoUrlString:videoUrlString];
}
- (void)releaseSelf {
[self.playerView releaseSelf];
}
- (void)replaceSuperView:(UIView *)selfSuperView {
[self.playerView replaceSuperView:selfSuperView];
}
- (void)removePlayer {
[self.playerView removePlayer];
[self.playerView.selfSuperView removeFromSuperview];
self.playerView = nil;
}
- (void)pauseVideo {
[self.playerView pauseVideo];
}
- (void)playVideo {
[self.playerView playVideo];
}
@end
具体实现内容到GitHub上下载源代码github地址:https://github.com/Janko0/JKAVPlayer,有什么问题欢迎提出(麻烦给个star)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。