Giter VIP home page Giter VIP logo

hcdcacheplayer's Introduction

HcdCachePlayer

Version License Platform Tag Travis CI Author

HcdCacheVideoPlayer实现了边下边播在线视频,并且能将在线视频缓存在本地,支持左右滑动手势来调整视频播放进度,上下滑动手势调节音量大小,并且支持全屏播放。此控件使用了Masonry自动布局来实现全屏播放时的界面布局。

Demo

特性

  • 使用AVPlayer开发,带缓存效果,对于同一个视频不用每次都去请求网络
  • 支持横、竖屏切换
  • 支持在视频上左右滑动调节播放进度
  • 视频右边上下滑动调节音量
  • 视频左边上下滑动调节亮度

安装

原始方法

可以可手动下载解压,然后将hcdCachePlayer文件夹拖入您的项目中,需要使用到MobileCoreServices.framework和AVFoundation.framework这两个库。

CocoaPods

采用CocoaPods方法安装,在您的Podfile文件中添加

pod 'HcdCachePlayer'

然后使用如下命令安装

pod install --verbose --no-repo-update

或者更新

pod update --verbose --no-repo-update

用法

在需要使用播放器的页面

#import "HcdCacheVideoPlayer.h"

然后创建一个View用于放置视频即可

HcdCacheVideoPlayer *play = [HcdCacheVideoPlayer sharedInstance];
UIView *videoView = [[UIView alloc] init];
videoView.frame = CGRectMake(0, 64, kScreenWidth, kScreenWidth * 0.5625);
[self.view addSubview:videoView];

NSURL *url = [NSURL URLWithString:@""];//您要播放的url地址

[play playWithUrl:[NSURL URLWithString:self.videoUrlStr]
         showView:videoView
     andSuperView:self.view
        withCache:YES];

TODO

使用AVPlayer封装带缓存的音乐播放器。 如果您觉得对您有所帮助您可以star一下,如果您在使用过程中发现什么bug欢迎Issues我。

第一次使用Cocoapods制作,所以写了一片文章做了个笔记: 《CocoaPods的制作过程》

hcdcacheplayer's People

Contributors

jvaeyhcd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hcdcacheplayer's Issues

指定时间播放,闪退

_play = [[HcdCacheVideoPlayer alloc] init];
[_play playWithUrl:[NSURL URLWithString:url showView:_videoImg andSuperView:self withCache:YES];
[_play seekToTime:3];
指定时间播放会闪退 进入下面的代码的时候 self.duration时间为0
seconds = MIN(seconds, self.duration);
[self.player pause];
[self.player seekToTime:CMTimeMakeWithSeconds(seconds, NSEC_PER_SEC) completionHandler:^(BOOL finished) {}

有一个视频网页能播放,到hcd里面播放不了

----loadingRequest----:<AVAssetResourceLoadingRequest: 0x1595daea0, URL request = <NSMutableURLRequest: 0x1596110f0> { URL: streaming://static.ojutao.com/video/wangyuan_bts_256k.mp4 }, request ID = 5, content information request = (null), data request = <AVAssetResourceLoadingDataRequest: 0x159627e70, requested offset = 145031168, requested length = 52609, requests all data to end of resource = YES, current offset = 145031168>>
大概就是上面这样的提示 放到项目中 只有声音没有画面
视频链接是 @"http://static.ojutao.com/video/wangyuan_bts_256k.mp4"
--------- 我是分割线-------
我的项目中请求该视频会弹出视频工具栏,但是时间等信息加载不出来。放在您的demo中是只会出现声音,没有画面

关于状态栏的横屏问题

[[UIApplication sharedApplication] setStatusBarOrientation:_currentOrientation animated:YES];
这句代码貌似不生效

有一些问题

我每次进下一个视频界面,那个进度条还停留在上一次播放的位置,等这一条视频加载完才会回到原点,这个bug很重要,谢谢!

请问更换url播放时怎么搞

请问更换url播放时怎么搞,我再次调- (void)playWithUrl:(NSURL *)url showView:(UIView *)showView andSuperView:(UIView *)superView;界面就卡着不动了

swift issues

i downloaded the demo and found you used swift to write code ,but it could't work . Can the HcdCachePlayer work by swift ? the finally i will play onLine but no cache ,how i to do

swift player issues

i download the demo, and i see you writed demo which used swift . but i do it ,it is wrong

无法缓存

你好,Jvaeyhcd:
发现视频有时无法缓存,我看你用的是NSURLConnection,现在都是用NSURLSession,你可以替换下吗?
能不能增加一个直接横屏播放的方法?
谢谢!

关于退出后台再进入的问题

播放的时候我暂停,然后退到后台再打开,视频又自己播放了。应该也是暂停的。。。还有就是这个播放器怎么控制它的高度,不管我怎么增大都不行呢

关于缓存视频

在缓存视频时,第一个视频可以缓存,第二和第三个视频在HcdVideoRequestTask中的self.taskArr始终会添加两次connection导致无法使视频从temp移到document,请问这个该怎么解决?

不会建立本地缓存文件,每次从网络取问题

如果一个视频断点多次下载, HcdVideoRequestTask类里响应网络完成函数进行处理,taskArr一直大于1, 不会建立本地缓存文件。
导致每次都从网络取数据。
你看是不是在HcdVideoRequestTask 的 connectionDidFinishLoading 里加上
[self.taskArr removeObject:connection];

[!] Unable to find a specification for `HcdCachePlayer`

目前发现的问题
1.通过 cocoaPods 安装报错
2.有时候快进快退播放时 按钮显示的 却是 暂停状态
3.用真机运行时 进入全屏模式,切换回竖屏模式的按钮无效

用心了,给颗星 望再接再励

急求!

选取的视频路径可以上传到服务器,但是在你这里无法播放

项目线上检测bug系统输出以下错误

出错定位 :
[dataRequest respondWithData:[filedata subdataWithRange:NSMakeRange((NSUInteger)startOffset- self.task.offset, (NSUInteger)numberOfBytesToRespondWith)]];
输出日志:
Fatal Exception: NSRangeException
0 CoreFoundation 0x1823c6db0 exceptionPreprocess
1 libobjc.A.dylib 0x181a2bf80 objc_exception_throw
2 CoreFoundation 0x1823c6cf8 -[NSException initWithCoder:]
3 Foundation 0x182d16ff0 -[NSData(NSData) subdataWithRange:]
4 EasyGo 0x100317690 -HcdLoaderURLConnection respondWithDataForRequest:
5 EasyGo 0x100317134 -HcdLoaderURLConnection processPendingRequests
6 EasyGo 0x100317fb4 -HcdLoaderURLConnection didReciveVideoDataWithTask:
7 EasyGo 0x1000e27c4 -HcdVideoRequestTask connection:didReceiveData:
8 CFNetwork 0x182b416a0 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke
9 Foundation 0x182d80540 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK

10 Foundation 0x182cd2870 -[NSBlockOperation main]
11 Foundation 0x182cc2e48 -[NSOperationInternal _start:]
12 Foundation 0x182d82934 __NSOQSchedule_f
13 libdispatch.dylib 0x181e1147c _dispatch_client_callout
14 libdispatch.dylib 0x181e16b84 _dispatch_main_queue_callback_4CF
15 CoreFoundation 0x18237cd50 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE

16 CoreFoundation 0x18237abb8 __CFRunLoopRun
17 CoreFoundation 0x1822a4c50 CFRunLoopRunSpecific
18 GraphicsServices 0x183b8c088 GSEventRunModal
19 UIKit 0x18758e088 UIApplicationMain
20 EasyGo 0x1002a6510 main (main.m:14)
21 libdispatch.dylib 0x181e428b8 (Missing)

运行后就崩溃,应该是约束的问题

第一次运行时出现的错误信息:reason: 'attempting to add unsupported attribute: (null)'
将HcdLightView单例的代码中的约束注释后,拖动滑块出现的错误信息
reason: 'AVPlayerItem cannot service a seek request with a completion handler until its status is AVPlayerItemStatusReadyToPlay.'

详细信息:关于第一次报错问题,我定位到错误是在创建HcdLightView单例的代码中,我把下面代码#warning -----注释了就可以运行起来了,但是拖动播放进步滑块时,还是会奔溃,我用的是Xcode8,请问怎么解决呀

  • (instancetype)sharedInstance {
    static HcdLightView *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    instance = [[HcdLightView alloc] init];
    [[UIApplication sharedApplication].keyWindow addSubview:instance];
    #warning -----
    [instance mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo([UIApplication sharedApplication].keyWindow);
    make.centerY.equalTo([UIApplication sharedApplication].keyWindow).offset(-5);
    make.width.mas_equalTo(155);
    make.height.mas_equalTo(155);
    }];
    });
    return instance;
    }

第二个错误注释了seekToTime:CMTimeMakeWithSeconds方法就不报错了

  • (void)seekToTime:(CGFloat)seconds {
    if (self.state == HCDPlayerStateStopped) {
    return;
    }

    seconds = MAX(0, seconds);
    seconds = MIN(seconds, self.duration);

    [self.player pause];
    #warning -----
    // [self.player seekToTime:CMTimeMakeWithSeconds(seconds, NSEC_PER_SEC) completionHandler:^(BOOL finished) {
    // self.isPauseByUser = NO;
    // [self.player play];
    // if (!self.currentPlayerItem.isPlaybackLikelyToKeepUp) {
    // self.state = HCDPlayerStateBuffering;
    //
    // self.actIndicator.hidden = NO;
    // [self.actIndicator startAnimating];
    // // [[XCHudHelper sharedInstance] showHudOnView:_showView caption:nil image:nil acitivity:YES autoHideTime:0];
    // }
    //
    // }];
    }

一些问题

导入你这个框架是不是就一定要同时导入Masonary?

还有就是,没有提供清除缓存的方法吗?

音频数据缓存数据在iOS12之前会出现问题

在iOS12之前。因为AVPlayer会触发多次请求,所以需要在- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response方法第一行加上sleep一秒钟,数据就能正常缓存了。但是在iOS12之后这个1秒的停留不能添加。否则会导致AVPlayer播放时发现数据没有,就会认为数据被损坏导致status认为Failed,总是第一次播放不成功。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.