Latest0.0.1
Homepagehttps://github.com/liudiange/playerCache
LicenseMIT
Platformsios 8.0
FrameworksUIKit
Authors

playerCache

一个边下边播的播放器api。支持mac 和iOS (mac版暂时不支持cocoapod 需要手动倒入)

该播放器实现的功能:

  • 调节声音
  • 播放
  • 暂停
  • 静音/正常播放 (调节声音 为0)
  • 监听缓存进度
  • 监听播放进度
  • 当前时间
  • 总的时间
  • 支持自定义的文件夹路径 (因为歌曲分高清、无损、普通的等等,名字可能相同,还有的歌曲名字可能不带类型)

优点

  • 可以实现边下边播
  • 完全自定义界面,只需实现api的方法

不足 以及待改进

  • 目前还不支持macos (只需要换一个缓存的文件夹路径)
  • 在巨人的肩膀上进行了修改和封装
  • 增加缓存大小的方法

需要注意点

  • 必须指明是否需要缓存(yes or no)
  • 自定义缓存文件的名字需要在 isNeedCache 前面书写 否则不起作用

安装

  • 直接将SULoader拖拽到工程中
  • cocoapod pod ‘SULoader’, ‘~> 0.0.1’

    使用

    音频

    NSURL * url = [NSURL URLWithString:[self songURLList][self.songIndex]];
    self.player = [[SUPlayer alloc]initWithURL:url];
    
       // 自定义的缓存歌曲名字歌曲,必须放在缓存的isNeedCache前使用,否则不起作用
    self.player.customCacheName = [self creatCustName:@"456" withUrl:url];;
    self.player.isNeedCache = YES;
    
    [self.player addObserver:self forKeyPath:@"progress" options:NSKeyValueObservingOptionNew context:nil];
    [self.player addObserver:self forKeyPath:@"duration" options:NSKeyValueObservingOptionNew context:nil];
    [self.player addObserver:self forKeyPath:@"cacheProgress" options:NSKeyValueObservingOptionNew context:nil];

    视频

    NSURL * url = [NSURL URLWithString:[self songURLList][self.songIndex]];
    self.player = [[SUPlayer alloc]initWithURL:url];
    
    // 自定义的缓存歌曲名字歌曲,必须放在缓存的isNeedCache否则不起作用
    //self.player.customCacheName = [self creatCustName:@"456" withUrl:url];;
    self.player.customCacheName = @"liudiange.mp4";
    self.player.isNeedCache = YES;
    self.player.layer.frame = self.view.frame;
    [self.view.layer addSublayer:self.player.layer];
    [self.player play];
    
    [self.player addObserver:self forKeyPath:@"progress" options:NSKeyValueObservingOptionNew context:nil];
    [self.player addObserver:self forKeyPath:@"duration" options:NSKeyValueObservingOptionNew context:nil];
    [self.player addObserver:self forKeyPath:@"cacheProgress" options:NSKeyValueObservingOptionNew context:nil];
    [self.player play];
    [self updateSongInfoShow];
    
    [self.progressSlider addTarget:self action:@selector(changeProgress:) forControlEvents:UIControlEventTouchUpInside];

    mac版的音频 (暂时不支持cocoapod)

    代码和iOS一下 但是需要注意一下这个部分

  • (NSString )tempFilePath {
    NSString
    path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    path = [path stringByAppendingPathComponent:@"MusicTemp.mp4"];
    return path;
    // return [[NSHomeDirectory( ) stringByAppendingPathComponent:@"tmp"] stringByAppendingPathComponent:@"MusicTemp.mp4"];
    }

  • (NSString *)cacheFolderPath {

    NSString *path = [NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES) lastObject];
    path = [path stringByAppendingPathComponent:@"MusicCaches"];
    //return [[NSHomeDirectory( ) stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"MusicCaches"];
    return path;
    }

#### mac版的视频
#### 代码和iOS一下 但是需要注意一下这个部分
  • (NSString )tempFilePath {
    NSString
    path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    path = [path stringByAppendingPathComponent:@"MusicTemp.mp4"];
    return path;
    // return [[NSHomeDirectory( ) stringByAppendingPathComponent:@"tmp"] stringByAppendingPathComponent:@"MusicTemp.mp4"];
    }

  • (NSString *)cacheFolderPath {

    NSString *path = [NSSearchPathForDirectoriesInDomains(NSMoviesDirectory, NSUserDomainMask, YES) lastObject];
    path = [path stringByAppendingPathComponent:@"MusicCaches"];
    //return [[NSHomeDirectory( ) stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"MusicCaches"];
    return path;
    }

    
    --具体产看demo

Latest podspec

{
    "name": "SULoader",
    "version": "0.0.1",
    "summary": "A short description of SULoader.",
    "homepage": "https://github.com/liudiange/playerCache",
    "license": "MIT",
    "authors": {
        "diange Liu": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/liudiange/playerCache.git",
        "tag": "v0.0.1"
    },
    "source_files": [
        "SULoader",
        "SULoader/**/*.{h,m}"
    ],
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This