• Stars
    star
    219
  • Rank 175,289 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A HTTP Media Caching Framework. It can cache FILE or HLS media. 音视频边播边缓存框架, 支持 HLS(m3u8) 和 FILE(mp4, mp3等).

SJMediaCacheServer

SJMediaCacheServer is a HTTP Media Caching Framework. It can cache FILE or HLS media.

Features

  • Support cache FILE and HLS media.
  • Support prefetch media.

Installation

pod 'SJUIKit/SQLite3', :podspec => 'https://gitee.com/changsanjiang/SJUIKit/raw/master/SJUIKit-YYModel.podspec'
pod 'SJMediaCacheServer'

使用介绍

Usage

  • Play
#import <SJMediaCacheServer/SJMediaCacheServer.h>

    NSURL *URL = [NSURL URLWithString:@"http://.../auido.mp3"];
    NSURL *playbackURL = [SJMediaCacheServer.shared playbackURLWithURL:URL];
    AVPlayer *player = [AVPlayer playerWithURL:playbackURL];
    [player play];
  • Prefetch
#import <SJMediaCacheServer/SJMediaCacheServer.h>
    
    [SJMediaCacheServer.shared prefetchWithURL:URL preloadSize:20 * 1024 * 1024 progress:^(float progress) {
        NSLog(@"%lf", progress);
    } completed:^(NSError * _Nullable error) {
        NSLog(@"%@", error);
    }];
    
    // The task to cancel the current prefetching.
    id<MCSPrefetchTask> task = [SJMediaCacheServer.shared prefetchWithURL:URL preloadSize:20 * 1024 * 1024 progress:^(float progress) {
        NSLog(@"%lf", progress);
    } completed:^(NSError * _Nullable error) {
        NSLog(@"%@", error);
    }];
    // cancel 
    [task cancel];
  • Download request configuration
    SJMediaCacheServer.shared.requestHandler = ^NSMutableURLRequest * _Nullable(NSMutableURLRequest * _Nonnull request) {
        [request addValue:@"value1" forHTTPHeaderField:@"header filed1"];
        [request addValue:@"value2" forHTTPHeaderField:@"header filed2"];
      return request;
    };
  • Other configuration
    @interface SJMediaCacheServer (Convert)

    /// Resolve the identifier of the resource referenced by the URL.
    ///
    ///     The resource identifier represents a unique resource. When different URLs references the same resource, you can set the block to resolve the identifier.
    ///
    ///     This identifier will be used to identify the local cache. The same identifier will references the same cache.
    ///
    @property (nonatomic, copy, nullable) NSString *(^resolveResourceIdentifier)(NSURL *URL); // URL参数不固定时, 请设置该block返回一个唯一标识符

    /// Encode the received data.
    ///
    ///     This block will be invoked when the download server receives the data, where you can perform some encoding operations on the data.
    ///
    @property (nonatomic, copy, nullable) NSData *(^writeDataEncoder)(NSURLRequest *request, NSUInteger offset, NSData *data); // 对下载的数据进行编码

    /// Decode the read data.
    ///
    ///     This block will be invoked when the reader reads the data, where you can perform some decoding operations on the data.
    ///
    @property (nonatomic, copy, nullable) NSData *(^readDataDecoder)(NSURLRequest *request, NSUInteger offset, NSData *data); // 对读取的数据进行解码

    @end


    @interface SJMediaCacheServer (Log)

    /// Whether to open the console log, only in debug mode. release mode will not generate any logs.
    ///
    ///     If yes, the log will be output on the console. The default value is NO.
    ///
    @property (nonatomic, getter=isEnabledConsoleLog) BOOL enabledConsoleLog; // 是否开启控制日志

    @end


    @interface SJMediaCacheServer (Cache)

    /// The maximum number of resources the cache should hold.
    ///
    ///     If 0, there is no count limit. The default value is 0.
    ///
    ///     This is not a strict limit—if the cache goes over the limit, a resource in the cache could be evicted instantly, later, or possibly never, depending on the usage details of the resource.
    ///
    @property (nonatomic) NSUInteger cacheCountLimit; // 个数限制

    /// The maximum length of time to keep a resource in the cache, in seconds.
    ///
    ///     If 0, there is no expiring limit.  The default value is 0.
    ///
    @property (nonatomic) NSTimeInterval maxDiskAgeForCache; // 保存时长限制

    /// The maximum size of the disk cache, in bytes.
    ///
    ///     If 0, there is no cache size limit. The default value is 0.
    ///
    @property (nonatomic) NSUInteger maxDiskSizeForCache; // 缓存占用的磁盘空间限制

    /// The maximum length of free disk space the device should reserved, in bytes.
    ///
    ///     When the free disk space of device is less than or equal to this value, some resources will be removed.
    ///
    ///     If 0, there is no disk space limit. The default value is 0.
    ///
    @property (nonatomic) NSUInteger reservedFreeDiskSpace; // 剩余磁盘空间限制

    /// Empties the cache. This method may blocks the calling thread until file delete finished.
    ///
    - (void)removeAllCaches; // 删除全部缓存
    @end

License

SJMediaCacheServer is released under the MIT license.

Feedback

Reference

More Repositories

1

SJVideoPlayer

iOS VideoPlayer MediaPlayer video player media player 短视频播放器 可接入 ijkplayer aliplayer alivodplayer plplayer
Objective-C
2,347
star
2

SJAttributesFactory

Simplify operation NSAttributedString, make writing easier. Attributes String Editing Factory. iOS 富文本编辑, 让代码更清晰. 文本编辑, 高度计算, 正则匹配等待... 简便操作, 让你爽到爆!
Objective-C
373
star
3

SJFullscreenPopGesture

Fullscreen pop gesture. OC&Swift. It is very suitable for the application of the video player. Support `cocoapods`. 只需`pod`即可自带全屏返回手势. 支持pod. 支持OC&Swift.
Objective-C
281
star
4

SJBaseVideoPlayer

video player. rotation, volume, brightness, rate, play, pause, stop, seekToTime, present.
Objective-C
117
star
5

SJSQLite3

DatabaseMapping. database mapping. Automatically create tables based on the model. 数据库模型映射. 自动建表, 自动更新表. 增删改查一句话搞定. 支持模糊查询, 各种插入和更新, 支持存储模型数组. pod SJSQLite3
Objective-C
114
star
6

SJSlider

滑块视图
Objective-C
94
star
7

SJLabel

一个支持匹配点击的 label . a label, Supports attributes text matching clicks.
Objective-C
51
star
8

SJPageViewController

A container view controller that manages navigation between pages of content, where each page is managed by a child view controller.
Objective-C
42
star
9

SJRouter

iOS Router
Objective-C
35
star
10

SJRecordVideo

record video and export. 短视频录制. 自由定制录制时间. 支持横竖屏录制&暂停&对焦&本地选取.
Objective-C
32
star
11

SJLoadingView

loading view.
Ruby
21
star
12

SJObserverHelper

SJObserverHelper, 观察者模式, 只需要观察即可, 不需要移除.
Objective-C
16
star
13

SJMP3Player

mp3 player, play while downloading. support set rate, and local cache. mp3播放器, 边下载边播放, 支持调速, 控制台操作.
Objective-C
15
star
14

LWZComponents

一些组件库
Objective-C
14
star
15

SJM3U8Downloader

Objective-C
14
star
16

SJBorderLineView

视图 或上或下或左或右 绘制一条线
Objective-C
6
star
17

SJAudioPlayer

A MP3 audio player. AVAudioEngine & AVAudioPlayerNode
Objective-C
6
star
18

SJMP3PlayWhileDownloadingProject

MP3歌曲边下载边播放, 支持调速, 控制台操作.
Objective-C
3
star
19

SJTransitionAnimator

Modal自定义转场动画
Objective-C
3
star
20

SJReciteWords

recite words
Objective-C
2
star
21

SJFrameLayout

Objective-C
2
star
22

SJUIKit

备份
Objective-C
2
star
23

iOS-Locks

Objective-C
1
star
24

SJPlaybackListController

SJVideoPlayer 播放列表控制器
Objective-C
1
star
25

PodIJKPlayer

Objective-C
1
star
26

SJSQLGenerator

最近在复习SQL语句, 为加深效果以及后期防止遗忘, 便使用OC写了一个便利构造SQL语句的库.
Objective-C
1
star