Giter VIP home page Giter VIP logo

vimediacache's Introduction

VIMediaCache

中文说明

Cache media file while play media using AVPlayerr.

VIMediaCache use AVAssetResourceLoader to control AVPlayer download media data.

CocoaPods

pod 'VIMediaCache'

Usage

Objective C

NSURL *url = [NSURL URLWithString:@"https://mvvideo5.meitudata.com/571090934cea5517.mp4"];
VIResourceLoaderManager *resourceLoaderManager = [VIResourceLoaderManager new];
self.resourceLoaderManager = resourceLoaderManager;
AVPlayerItem *playerItem = [resourceLoaderManager playerItemWithURL:url];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];

Swift

let url = URL(string: "https://mvvideo5.meitudata.com/571090934cea5517.mp4")
let resourceLoaderManager = VIResourceLoaderManager()
let playerItem = resourceLoaderManager.playerItem(with: url)
let player = AVPlayer(playerItem: playerItem)

Contact

[email protected]

License

MIT

vimediacache's People

Contributors

ceekay1991 avatar cp-satish-v avatar kelaking avatar kim4apple avatar satishvekariya avatar smhjsw avatar vitoziv avatar wenxinyu999 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vimediacache's Issues

关于在iOS9系统上切换playerItem导致应用程序页面卡死情况,可复现

经过模拟器和真机测试,在iOS9操作系统上,切换由resourceLoaderManager创建的playerItem时,会导致整个页面卡死。

如果使用系统的AVPlayerItem playerItemWithURL:则不会出现这个问题,切换过程比较流畅,并且视频可以正常播放。

在模拟器上可以复现,希望作者可以关注。

可以设置cache的大小和时间吗?

现在使用VICacheManager,可以设置缓存的大小或者特定时间可以自动清理一下吗?因为有时候用户点击太多视频了缓存的容量比较大,但用户又没有手动去清除,谢谢!

crash when no free space is left on the file system(iOS 8.1.3)

- (void)setContentInfo:(VIContentInfo *)contentInfo {
    self.internalCacheConfiguration.contentInfo = contentInfo;
    
    [self.writeFileHandle truncateFileAtOffset:contentInfo.contentLength];
    [self.writeFileHandle synchronizeFile];
}

these codes lead to crashes,when when no free space is left on the file system(iOS 8.1.3)
Could you please add "@Try{}@catch{}" or judgement before handle files,like "truncateFileAtOffset:",and same to other codes in the project.
thanks.

直接崩溃

2017-06-02 09:16:28.148 BabyBox[2167:21365] *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle truncateFileAtOffset:]: Invalid argument'

按照demo来的,只写了demo的代码。直接崩溃了,这里是视频地址

@[
         @"http://lavaweb-10015286.video.myqcloud.com/%E5%B0%BD%E6%83%85LAVA.mp4",
	  @"http://lavaweb-10015286.video.myqcloud.com/lava-guitar-creation-2.mp4",
	  @"http://lavaweb-10015286.video.myqcloud.com/hong-song-mei-gui-mu-2.mp4",
	  @"http://lavaweb-10015286.video.myqcloud.com/ideal-pick-2.mp4"
	  ];

麻烦看看

ui 卡死

demo 中的 toggle 按钮点击后ui 卡死 ,我是用的10.3 模拟器。谢谢帮助

请教一个问题

看了您的这个代码之后,自己也利用AVAssetResourceLoader类写了一个边播放边缓存边下载的例子,但是现在遇到一个问题向您请教一下,就是第一次播放时正常的,但是缓存下来的数据再次打开的时候就提示文件被损坏报NSLocalizedFailureReason=This media may be damaged.错误,但是找了好久也没找到哪里出问题了,能帮忙指教下吗?

seek 导致的问题

若音频 seek 到仍未缓存好的位置,播放的内容仍然为音频的起始位置。

支持简单的 Cache 策略

看了下实现,没有找到哪里支持下面的缓存策略:

  1. 最大缓存 size;
  2. 达到最大缓存限制后的替换策略。

一些功能上的疑问

  1. VIMediaCache 的默认缓存文件名为 URL 的 absoluteString,但是因为 cdn 加速,可能导致同一视频文件被缓存多次,因为它们的主机不同;
  2. 缓存文件是以可播放的 .mp4 直接存放于 tmp 目录下,在越狱手机上,可以直接拿到该视频文件进行播放。如果视频文件是有版权保护的话,可能有损公司的利益。再者,tmp 目录下的文件会被系统不定期清理,如果想要达到缓存了的视频能够离线播放,是不是应该将其放在 Library/Caches 这个目录下呢?在将 NSData 写入文件之前可否先进行加密了?

感谢贵公司的开源精神,VIMediaCache 帮助我完成了最近项目上视频缓存的需求,鞠躬......

您好

您好 我想请问下我如何能做到一边播放音频一边缓存呢?因为我看这个demo是下载下来之后才可以播放的

CPU 占用很高

设备 iPhone6 开始播放 之后 cpu 直接飙升到100 % 发热量感人

某些视频偶尔不能正常播放,卡在固定的位置

我在播放一个视频,要么能正常播放,要么会卡住,仔细看了下代码,发现总是卡住一个固定位置
<AVAssetResourceLoadingDataRequest: 0x1c0005860, requested offset = 933888, requested length = 15259, requests all data to end of resource = YES, current offset = 933888>
如某个视频,一直卡在933888这里,不知道是不是视频编码的原因

切换网络

当断开网络, 缓存播放完之后 会卡住不动。
在连接网络的时候,不会主动缓存。播放器会卡住不动

更换播放源时会卡住

同一播放器,当更换播放源调用replaceCurrentItem时,会卡住
resourceLoaderManager = VIResourceLoaderManager()
playerItem = resourceLoaderManager?.playerItem(with: url)
player?.replaceCurrentItem(with: playerItem)

因为不想重复创建 AVPlayer,所以使用的replaceCurrentItem。
xcode 8.3
swift 3.1
模拟器 iPhone7

关于视频播放过程中seek导致视频无法进行“完全”缓存问题

作者,你好

先简单描述一下我的需求。在视频播放页面,有一个“缓存状态”的Image,可以根据当前视频缓存(不是播放)进度,修改为“缓存中”和“已缓存”。

目前,我是根据mediaCacheDidChanged中的configuration.progress获取缓存状态,如果大于等于1,则认为该视频已经缓存成功,将“缓存状态”的image从“缓存中”改为“已缓存”。

你在 文章 中关于“分片缓存”的处理我是理解的。

但是按照我的需求,如果用户在播放过程中进行了seek过长,就会导致播放器不会针对进度条左侧未请求到的数据的range进行重新请求,出现的状况就是,视频已经播放完成,“缓存状态”的Image还是处于“缓存中”。

我在VIMediaCache的VIMediaDownloader.h中发现一个downloadFromStartToEnd,经过搜索,此方法没有被使用,想请教这个方法是否可以解决我的问题?如果不能,是否可以提供一个你的思路?

感谢。

有时候视频的首帧出来非常非常慢

有时候视频的首帧出来非常非常慢,而且我看了视频已经预加载了,而且视频格式是适应于流媒体的,请问是什么情况?

有时候还会报
Domain=AVFoundationErrorDomain Code=-11829 "打不开" UserInfo={NSLocalizedFailureReason=此媒体可能已损坏。, NSLocalizedDescription=打不开

url 中包含中文时会crash

VIResourceLoaderManager

originURL = [NSURL URLWithString:queryItem.value];

改成

originURL = [NSURL URLWithString:[queryItem.value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

change local file to cache

i want to change my local record files to cache in order to reduce network flow.
what should i do with the VICacheConfiguration

使用个别带有参数的视频URL地址时出现URL分析错误的BUG

我的视频地址:https://09-lvl3-pdl.vimeocdn.com/01/1685/5/133428888/392193519.mp4?expires=1515144009&token=0ae276f099179fbac4e16

因为是三方的视频地址,存在&链接的参数,
在resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest方法中,components.queryItems中最后一个对象并非我的完整原链接,导致最终程序认为链接无法支持未能加载视频

[对于这个问题我在本地进行了一定修改,不过也是针对于我使用的URL进行调整可以顺利解决该问题,代码如下:
a8dc6df7-0e2d-49f1-a1c4-691b6e63d6b9

请作者酌情处理一下该问题,要不然这套封装使用很简易的视频缓存框架反倒因为这种问题无法使用很恼火啊~

有播放進度, 但畫面不會更新

有時候前面會播一下下然後就卡住不播
但是 addPeriodicTimeObserverForInterval 的時候
check playerItem.currentTime 卻有更新
不特定檔案..

内存管理问题

用ipad mini 播放了较大的视频(400M )时,会出现内存警告。

部分视频下载时出现本地缓存文件错误,导致播放器超时,无法播放

2018-03-12 14:42:41.746407+0800 XXX[609:157609] player status 2, rate 1, error: Error Domain=NSURLErrorDomain Code=-1001 "请求超时。" UserInfo={NSLocalizedDescription=请求超时。, NSUnderlyingError=0x1c08560e0 {Error Domain=NSOSStatusErrorDomain Code=-1001 "(null)"}}

2018-03-12 14:42:41.746697+0800 XXX[609:157609] player error Error Domain=NSURLErrorDomain Code=-1001 "请求超时。" UserInfo={NSLocalizedDescription=请求超时。, NSUnderlyingError=0x1c08560e0 {Error Domain=NSOSStatusErrorDomain Code=-1001 "(null)"}}

大家有没有遇到同样的情况呢?

视频资源包括mp4和m3u8两种格式,如何避免m3u8走缓存

作者,你好。

我们的视频资源包括mp4和m3u8两种格式,在视频切换过程中,如果出现m3u8格式,VIMediaCache依然会对视频资源进行下载,但播放器显示无法播放。

是否可以/需要在哪里添加一个判断,使得在使用VIMediaCache的时候,可以自主选择需要下载的资源类型?我尝试在以下部分代码中添加m3u8类型判断,但是没有成功。

#pragma mark - VIURLSessionDelegateObjectDelegate

  • (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
    NSString *mimeType = response.MIMEType;
    // Only download video/audio data
    if ([mimeType rangeOfString:@"video/"].location == NSNotFound &&
    [mimeType rangeOfString:@"audio/"].location == NSNotFound &&
    [mimeType rangeOfString:@"application"].location == NSNotFound) {
    completionHandler(NSURLSessionResponseCancel);
    } else {

... ...

缓存文件空间浪费比较多

- (void)setContentInfo:(VIContentInfo *)contentInfo error:(NSError **)error {
    self.internalCacheConfiguration.contentInfo = contentInfo;
    @try {
        [self.writeFileHandle truncateFileAtOffset:contentInfo.contentLength];
        [self.writeFileHandle synchronizeFile];
    } @catch (NSException *exception) {
        NSLog(@"read cached data error %@", exception);
        *error = [NSError errorWithDomain:exception.name code:123 userInfo:@{NSLocalizedDescriptionKey: exception.reason, @"exception": exception}];
    }
}

这里的truncateFileAtOffset一开始就会占用视频的fullsize。如果用这个库在列表页做预加载,会非常浪费空间。 一个短视频如果有8M,预加载只下载前面800K,也需要用掉8M的空间。 其实这里不truncate也是完全没有什么问题的。

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.