Skip to content

音视屏播放框架XYQPlayer,支持播放、暂停、缓存

License

Notifications You must be signed in to change notification settings

xiayuanquan/XYQPlayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XYQPlayer

音视屏播放框架XYQPlayer,支持播放、暂停、缓存

一、前缀

一直都想好好学学音视频这方面的知识,抽了几个周末参考一些资料,尝试着写了一个简易的音视频播放框架,支持音视频播放、视频截图、音乐缓存。
其实吧,也就 是尽可能的封装罢了,方便以后自己使用。目前只是开始,可能有些不足,后续会继续优化。
可以在github上下载,地址是https://github.com/xiayuanquan/XYQPlayer 。
当然也请多多关注本博主夏远全:http://www.cnblogs.com/XYQ-208910/p/6685412.html 
概念参考我的这篇博文:http://www.cnblogs.com/XYQ-208910/p/5662655.html 
我的简书地址:http://www.jianshu.com/p/1f8f434cfcba

   

二、框架

1、截图

image

2、文件

XYQAllHeader.h:所有的头文件

XYQAudioTool.h/m:音频播放工具类,播放包括短音频和音乐

XYQAudioToolView.h/m:音频播放界面类,显示播放音乐的界面,播放、暂停、光盘旋转

XYQAudioToolLoader.h/m:音频下载类,缓存音乐到本地

XYQCachesManager.h/.m:缓存管理类,计算缓存大小、清除缓存

XYQMovieTool.h/m:视频播放工具类,直接显示播放界面、还有截屏功能

XYQHUDView.h/m:弹框提示,包括文本提示、下载进度提示

XYQTimeProgress.h/m:音乐播放时间进度条

UIImage+XYQCornerRadius.h/m:对图片进行处理的类

Source.bundle:资源包,存放图片icon

3、依赖

image

三、音乐播放和缓存逻辑

image

四、视频播放方式

image

五、音频播放test

#import "PlayMusicViewController.h"
#import "XYQAllHeader.h"
@interface PlayMusicViewController ()
@property (strong,nonatomic)XYQAudioToolView *audioPlayerView;
@end

@implementation PlayMusicViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"清除缓存" style:UIBarButtonItemStylePlain target:self action:@selector(clearCache)];

    //1、网络音乐(此处需要给出准确的url,我的这个不可以用,只是给个参考的样式)
    //[self testPlay_Local_URL_Music:@[@"http://120.25.226.186:32812/xxx/minion_02.mp3"]];

    //2、本地音乐
    [self testPlay_Bundle_Music:[self musicArray]];
}

//测试创建音乐播放器(播放沙盒本地音乐包括从网络音乐下载缓存)
- (void)testPlay_Local_URL_Music:(NSArray *)musicFileLinkArray{

    self.audioPlayerView = [XYQAudioToolView openAudioPlayerView:musicFileLinkArray  audioPlayerViewController:self];
    self.audioPlayerView.diskIsHide = YES;
}

//测试创建音乐播放器(播放bundle根目录下的音乐)
- (void)testPlay_Bundle_Music:(NSArray *)musicNameArray{

    self.audioPlayerView = [XYQAudioToolView openAudioPlayerView:musicNameArray  audioPlayerViewController:self];
    self.audioPlayerView.diskIsHide = YES;
}

//Bundle根目录子下所有的音乐文件名
- (NSArray *)musicArray{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Musics" ofType:@"plist"];
    NSArray *musicNameArr = [NSArray arrayWithContentsOfFile:path];
    return musicNameArr;
}

//清除缓存
- (void)clearCache{
    [XYQCachesManager clearFileCaches];
}

//关闭播放器
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.audioPlayerView dismissAudioPlayerView];
}

六、视频播放test

//  PlayMovieViewController.m
//  XYQPlayer
//
//  Created by 夏远全 on 2017/4/9.
//  Copyright © 2017年 夏远全. All rights reserved.
//

#import "PlayMovieViewController.h"
#import "XYQAllHeader.h"
@interface PlayMovieViewController ()
@end

@implementation PlayMovieViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    //1、push网络视频
    //[XYQMovieTool pushPlayMovieWithNetURL:@"http://120.25.226.186:32812/resources/videos/minion_02.mp4" viewController:self];

    //2、push本地视频
    NSString *localMoive = [[NSBundle mainBundle] pathForResource:@"localmovie" ofType:@"mp4"];
    [XYQMovieTool pushPlayMovieWithLocalURL:localMoive viewController:self];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    //1、present网络视频
    //[XYQMovieTool presentPlayMovieWithNetURL:@"http://120.25.226.186:32812/resources/videos/minion_02.mp4" viewController:self];

    //2、push本地视频
    NSString *localMoive = [[NSBundle mainBundle] pathForResource:@"localmovie" ofType:@"mp4"];
    [XYQMovieTool presentPlayMovieWithNetURL:localMoive viewController:self];
}

//关闭播放器
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [XYQMovieTool cancelPlay];
}
@end

   

七、cocoaPods支持

pod search 'XYQPlayer'

image

八、演示截图

1、音乐

image

image

image

image

2、视频

push

image

present

image

About

音视屏播放框架XYQPlayer,支持播放、暂停、缓存

Resources

License

Stars

Watchers

Forks

Packages

No packages published