当前位置:   article > 正文

视频播放器AVPlayer_免费免播放器在线视频av

免费免播放器在线视频av
1、采用AVPlayer进行封装
2、通过单例视频管理类全局控制视屏的播放暂停和移除视频view
3、播放视图和工具条独立封装,完全解耦

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)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/282631
推荐阅读
相关标签
  

闽ICP备14008679号