![(banner)](https://camo.githubusercontent.com/59a80466e9d0c4e8d042f095fcd8236795231156363b150f3e380220d000c0e5/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f62616e6e65722d736d616c6c2e706e67)
![Support](https://camo.githubusercontent.com/cdfad5851ecc4540b492b708fefac532ef55de026d75f450c3284314a791694d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737570706f72742d25323056522532303336302543322542302532302d6f72616e67652e737667)
- SGPlayer是一个强大的媒体资源播放器框架,内核由AVPlayer、FFmpeg组成,通过播放内核选择策略动态选择最优播放内核,并可以自定义内核选择策略。
- 支持VR全景视频播放
- 支持手势、传感器操控VR全景视频
- 支持VR眼镜双眼模式,并具有边缘畸变校正功能
- 支持iOS、macOS、tvOS
- 支持H.264硬解解码(VideoToolBox)
- 支持选择软件解码、硬件解码
- 支持RTMP、RTSP等直播流
- 支持所有常见媒体格式
- 支持选择视频图像缩放方式
- 支持选择音频轨道
- 支持后台播放
- 支持调整音频输出音量
- 支持无损视频截图
- 支持Bitcode
- 极简的事件通知机制
// iOS
git clone https://github.com/libobjc/SGPlayer.git
cd SGPlayer
sh compile-build.sh iOS
// macOS
git clone https://github.com/libobjc/SGPlayer.git
cd SGPlayer
sh compile-build.sh macOS
// tvOS
git clone https://github.com/libobjc/SGPlayer.git
cd SGPlayer
sh compile-build.sh tvOS
git clone [email protected]:libobjc/SGPlayer.git
cd SGPlayer
git submodule update --init --recursive
// 将FFmpeg编译出的.a静态库分别放在对应目录
/SGPlayer/Classes/Core/SGFFPlayer/ffmpeg/lib-iOS // iOS
/SGPlayer/Classes/Core/SGFFPlayer/ffmpeg/lib-macOS // macOS
/SGPlayer/Classes/Core/SGFFPlayer/ffmpeg/lib-tvOS // tvOS
![ffmpeg-libs](https://camo.githubusercontent.com/fa79e0b3d1638f1fb5f78b4440b27056d32398e9d0bff1712dfc74e28db78839/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f66666d7065672d6c6962732e706e67)
- SGPlayer.framework
- SGPlatform.framework Optional
- CoreMedia.framework
- AudioToolBox.framework
- VideoToolBox.framework
- libiconv.tbd
- libbz2.tbd
- libz.tbd
- SGPlayer.framework
- SGPlatform.framework Optional
- CoreMedia.framework
- AudioToolBox.framework
- VideoToolBox.framework
- VideoDecodeAcceleration.framework
- libiconv.tbd
- libbz2.tbd
- libz.tbd
- libizma.tbd
self.player = [SGPlayer player];
// 注册事件通知
[self.player registerPlayerNotificationTarget:self stateAction:@selector(stateAction:) progressAction:@selector(progressAction:) playableAction:@selector(playableAction:) errorAction:@selector(errorAction:)];
// 视频画面点击事件
[self.player setViewTapAction:^(SGPlayer * _Nonnull player, SGPLFView * _Nonnull view) {
NSLog(@"player display view did click!");
}];
// 播放普通视频 (2种方式2选1即可)
[self.player replaceVideoWithURL:contentURL]; // 方式1
[self.player replaceVideoWithURL:contentURL videoType:SGVideoTypeNormal]; // 方式2
// 播放VR全景视频
[self.player replaceVideoWithURL:contentURL videoType:SGVideoTypeVR];
// 播放
[self.player play];
// 三种预设播放内核选择策略
self.player.decoder = [SGPlayerDecoder defaultDecoder]; // 默认配置,混合使用AVPlayer和FFmpeg,根据容器格式动态选择播放内核
self.player.decoder = [SGPlayerDecoder AVPlayerDecoder]; // 仅使用AVPlayer
self.player.decoder = [SGPlayerDecoder FFmpegDecoder]; // 仅使用FFmpeg
// 单个容器格式单独配置示例
self.player.decoder.mpeg4Format = SGDecoderTypeFFmpeg; // 使用FFmpeg播放mp4文件
// 开启FFmpeg硬解
self.player.decoder.ffmpegHardwareDecoderEnable = YES;
// 进入VR眼镜模式
self.player.displayMode = SGDisplayModeBox;
// 设置后台播放模式
// 如果需要后台播放,需将项目的Background Modes打开并勾选Audio选项, 并将AVAudioSession的Category设为AVAudioSessionCategoryPlayback
self.player.backgroundMode = SGPlayerBackgroundModeAutoPlayAndPause; // 自动暂停及恢复
self.player.backgroundMode = SGPlayerBackgroundModeContinue; // 继续播放
![ios-i-see-fire](https://camo.githubusercontent.com/4b1cccdf8b7451d3183c91a0051d284e8a0f89dd3a1c14f2c6ee75892a7b1d15/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f696f732d692d7365652d666972652e676966)
![ios-google-vr](https://camo.githubusercontent.com/accd02a399cc1aa2d84fb076fe1a93357edaaac43d22fca5f72aad32afabba33/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f696f732d676f6f676c652d76722e676966)
![ios-google-vr-box](https://camo.githubusercontent.com/92fe3d20d127173cf80d3a2ac4c8fbb7a84d95c689667a5d51769fc2e4aa0b8f/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f696f732d676f6f676c652d76722d626f782e676966)
![mac-i-see-fire](https://camo.githubusercontent.com/b352066db5b66cc61a01707cb13607e09a3078a5c94e93aa5ad15507d7f997f4/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f6d61632d676f6f676c652d76722e676966)
![mac-google-vr](https://camo.githubusercontent.com/b352066db5b66cc61a01707cb13607e09a3078a5c94e93aa5ad15507d7f997f4/68747470733a2f2f636f64696e672e6e65742f752f30783031303130312f702f7265736f757263652d7075626c69632f6769742f7261772f6d61737465722f5347506c617965722f6d61632d676f6f676c652d76722e676966)