-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sujia
committed
Nov 22, 2016
1 parent
3c98be9
commit 90b7342
Showing
47 changed files
with
4,499 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
# Created by https://www.gitignore.io/api/objective-c | ||
|
||
### Objective-C ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
|
||
## Other | ||
*.xccheckout | ||
*.moved-aside | ||
*.xcuserstate | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
Pods/ | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md | ||
|
||
fastlane/report.xml | ||
fastlane/screenshots | ||
|
||
### Objective-C Patch ### | ||
*.xcscmblueprint | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,171 @@ | ||
# ksyhttpcache_ios | ||
# 金山云Android HTTPCache SDK | ||
金山云ios平台http缓存SDK,可方便地与播放器集成,实现http视频边播放边下载(缓存)功能。ksyun http cache sdk for ios platform, it's easy to integrated with media players to provide caching capability when watching http videos. | ||
|
||
## 1. 产品概述 | ||
金山云ios HTTPCache SDK可以方便地和播放器进行集成,提供对HTTP视频边播放缓存的功能,缓存完成的内容可以离线工作。 | ||
|
||
KSY HTTPCache与播放器及视频服务器的关系如下图: | ||
![](https://github.com/sujia/image_foder/blob/master/ksy_http_cache.png) | ||
|
||
KSY HTTPCache相当于本地的代理服务,使用KSY HTTPCache后,播放器不直接请求视频服务器,而是向KSY HTTPCache请求数据。KSY HTTPCache在代理HTTP请求的同时,缓存视频数据到本地。 | ||
|
||
## 2.功能说明 | ||
它可以很方便的和播放器进行集成,提供以下功能: | ||
1. http点播视频边缓存边播放,且播放器可从通过回调得到缓存的进度以及错误码 | ||
|
||
2. 缓存完成的视频,再次点播时可以离线播放,不再请求视频server | ||
|
||
3. 查询缓存已完成的文件列表, 缓存未完成的文件列表 | ||
|
||
4. 清除缓存(清除所有缓存,或删除某个url缓存) | ||
|
||
5. 提供两种缓存策略供选择(限制缓存区总大小或者限制缓存文件总个数) | ||
|
||
|
||
## 3.下载和使用 | ||
下载framework目录下的KSYHTTPCache.framework,并添加到工程中。 | ||
|
||
为了保证正常工作,推荐在AppDelegate中开启和关闭服务,如下: | ||
```objectivec | ||
#import <KSYHTTPCache/KSYHTTPProxyService.h> | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
[[KSYHTTPProxyService sharedInstance] startServer]; | ||
return YES; | ||
} | ||
- (void)applicationDidEnterBackground:(UIApplication *)application { | ||
[[KSYHTTPProxyService sharedInstance] stopServer]; | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application { | ||
[[KSYHTTPProxyService sharedInstance] startServer]; | ||
} | ||
|
||
``` | ||
proxy与播放器的集成如下所示,通过getProxyUrl接口获得代理播放地址,进行播放。 | ||
```objectivec | ||
//get proxy url from ksyhttpcache | ||
NSString *proxyUrl = [[KSYHTTPProxyService sharedInstance] getProxyUrl:@"http://maichang.kssws.ks-cdn.com/upload20150716161913.mp4"]; | ||
//init player with proxy url | ||
KSYMoviePlayerController *player = [[KSYMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:proxyUrl]]; | ||
//play the video | ||
[player prepareToPlay]; | ||
``` | ||
|
||
使用以上方法,proxy将采用默认配置。可采用如下方法自定义配置(需在startServer前设置): | ||
|
||
- 设置缓存区位置 | ||
```objectivec | ||
(void)setCacheRoot:(NSString *)cacheRoot | ||
``` | ||
|
||
- 缓存区大小限制策略(文件个数限制、文件总大小限制),目前这两种策略只能二选一,且策略在每次播放完成或者退出播放时生效。 | ||
|
||
- 使用限制文件总大小的策略,默认使用的是该策略,且缓存大小为500M | ||
|
||
```objectivec | ||
-(void)setMaxCacheSizeLimited:(long long)maxCacheSize; | ||
``` | ||
|
||
- 使用限制文件总个数的策略 | ||
|
||
```objectivec | ||
-(void)setMaxFilesCountLimited:(NSInteger)maxFilesCount; | ||
``` | ||
|
||
- 状态监听 | ||
|
||
- KSYHTTPCache发生错误时的发送CacheErrorNotification通知 | ||
|
||
```objectivec | ||
CacheErrorNotification | ||
``` | ||
|
||
- KSYHTTPCache缓存进度发送变化时发送CacheStatusNotification通知 | ||
|
||
```objectivec | ||
CacheStatusNotification | ||
``` | ||
|
||
注册notification监听 | ||
```objectivec | ||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(mediaCacheDidChanged:) | ||
name:CacheStatusNotification | ||
object:nil]; | ||
``` | ||
去掉notification监听 | ||
```objectivec | ||
[[NSNotificationCenter defaultCenter] removeObserver:self | ||
name:CacheStatusNotification | ||
object:nil]; | ||
``` | ||
## 4.其他接口说明 | ||
获取代理后的播放地址 | ||
```objectivec | ||
(NSString*)getProxyUrl:(NSString*)url; | ||
``` | ||
启动server | ||
```objectivec | ||
(void)startServer; | ||
``` | ||
关闭server | ||
```objectivec | ||
(void)stopServer; | ||
``` | ||
查询server是否在运行状态 | ||
```objectivec | ||
(BOOL)isRunning; | ||
``` | ||
删除缓存区所以文件 | ||
```objectivec | ||
(void)deleteAllCachesWithError:(NSError**)error; | ||
``` | ||
删除某个url对应的缓存文件 | ||
```objectivec | ||
(void)deleteCacheForUrl:(NSURL*)url error:(NSError**)error; | ||
``` | ||
查询某个url缓存是否完成 | ||
```objectivec | ||
-(BOOL)isCacheCompleteForUrl:(NSURL*)url; | ||
``` | ||
获得缓存已完成文件列表 | ||
```objectivec | ||
-(NSArray*)getAllCachedFileListWithError:(NSError**)errors; | ||
``` | ||
获得缓存未完成文件列表 | ||
```objectivec | ||
-(NSArray*)getAllCachingFileListWithError:(NSError**)error; | ||
``` | ||
获得url对应缓存文件的路径 | ||
```objectivec | ||
-(NSString*)getCachedFilePathForUrl:(NSURL *)url; | ||
``` | ||
获得url对应缓存未完成url对应的cache fragment | ||
```objectivec | ||
-(NSArray*)getCacheFragmentForUrl:(NSURL *)url error:(NSError **)error; | ||
``` | ||
查询缓存区位置 | ||
```objectivec | ||
-(NSString*)cacheRoot; | ||
``` | ||
|
||
获得缓存区路径 | ||
|
||
## 5.其他文档 | ||
请见[wiki](https://github.com/ksvc/ksyhttpcache_ios/wiki) | ||
|
||
## 6.反馈与建议 | ||
- 主页:[金山云](http://www.ksyun.com/) | ||
- 邮箱:<[email protected]> | ||
- QQ讨论群:574179720 | ||
- Issues:https://github.com/ksvc/ksyhttpcache_ios/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// HTTPCacheDefines.h | ||
// KSYHTTPCache | ||
// | ||
// Created by sujia on 2016/10/31. | ||
// Copyright © 2016年 kingsoft. All rights reserved. | ||
// | ||
|
||
#ifndef HTTPCacheDefines_h | ||
#define HTTPCacheDefines_h | ||
|
||
extern NSString *CacheStatusNotification; | ||
extern NSString *CacheErrorNotification; | ||
|
||
extern NSString *CacheURLKey; | ||
extern NSString *CacheFragmentsKey; | ||
extern NSString *CacheContentLengthKey; | ||
extern NSString *CacheFilePathKey; | ||
|
||
extern NSString *CacheErrorCodeKey; | ||
|
||
/** | ||
* 错误码 | ||
*/ | ||
typedef NS_ENUM(NSInteger, KSYHTTPCacheErrorCode) { | ||
OK = 0, | ||
UnknownError = 1, | ||
|
||
//cache | ||
OpenCacheError = 1001, | ||
ReadCacheError = 1002, | ||
WriteCacheError = 1003, | ||
CloseCacheError = 1004, | ||
DeleteCacheError = 1005, | ||
SaveConfigError = 1006, | ||
|
||
//source | ||
HeadRequestError = 2001, | ||
HTTPDownloadError = 2002, | ||
|
||
//server | ||
StartServerError = 3001, // failed to start local http server | ||
InvalidRequestError = 3002, //malformed HTTP request | ||
UnknowHTTPMethodError = 3003, //a HTTP request with a method other than GET or HEAD | ||
}; | ||
|
||
typedef NS_ENUM(NSInteger, KSYCacheStrategy) { | ||
MaxCacheSizeLimited = 0, | ||
MaxFilesCountLimited = 1, | ||
}; | ||
|
||
#endif /* HTTPCacheDefines_h */ |
Oops, something went wrong.