CocoaPods trunk is moving to be read-only. Read more on the blog, there are 17 months to go.

ZonPlayer 1.1.0

ZonPlayer 1.1.0

Maintained by ZeroOnet.



ZonPlayer 1.1.0

ZonPlayer

ZonPlayer is a player library base on AVPlayer with cache and remote control support in iOS. For convenience, we defined interfaces can be called by chain.

Features

  • Configure AVAudioSession asynchronously to prevent the main thread from hang.
  • Support 3rd-party cache like VIMediaCache. There are presetted with ZPC.DownloadThenPlay and ZPC.Streaming(base on AVAssetResourceLoader).
  • Manage now playing info and remote control command.
  • Use plugin to intercept progress for streaming playback.
  • Retry automatically if then player has an error, eg: media services were reset.

Usage

    let player: ZonPlayable = ZonPlayer.player(URLConvertible)
        .session(ZPSessionable)
        .cache(ZPCacheable) // Conform ZPCacheable to customize cache category.
        .remoteControl(self) { wlf, payload in // Conform ZPRemoteControllable to customize background playback controller.
            payload.title(String).artist(String)....
        }
        .onPaused(self) { wlf, payload in // Conform ZPObservable to listen player.
        }
        .activate(in: ZonPlayerView)

    // Conform ZPControllable to control player instance.
    player.pause()
    player.play()
    player.seek(to: 0)
    // ...

    // Conform ZPGettable to read player status.
    player.currentTime
    player.duration
    player.url
    // ...

Integrate 3rd-party cache:

import VIMediaCache

final class TestCache: ZPCacheable {
    let manager = VIResourceLoaderManager()

    func prepare(url: URL, completion: @escaping (Result<AVURLAsset, ZonPlayer.Error>) -> Void) {
        let item = manager.playerItem(with: url).unsafelyUnwrapped
        let asset = (item.asset as? AVURLAsset).unsafelyUnwrapped
        completion(.success(asset))
    }
}

func play() {
    let player = ZonPlayer.player(url).cache(TestCache())
}

Notice: before using ZPC.Streaming, it is advisable to ensure that the URL supports random access to avoid potential unexpected issues. Below is the official documentation explanation for isByteRangeAccessSupported:

If this property is not true for resources that must be loaded incrementally, loading of the resource may fail. Such resources include anything that contains media data.

Requirements

  • iOS 12.0 or later
  • Swift 5.0 or later

Installation

CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!

target 'MyApp' do
  pod 'ZonPlayer', '~> 1.0.0'
end

Carthage

github "ZeroOnet/ZonPlayer" ~> 1.0.0

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • Add [email protected]:ZeroOnet/ZonPlayer.git
  • Select "Up to Next Major" with "1.0.0"

Author

ZeroOnet, [email protected]

Blogs

从头撸一个播放器 I —— ZonPlayer 需求分析及接口设计
从头撸一个播放器 II —— 音频会话、远程控制和播放器实现
从头撸一个播放器 III —— 缓存
从头撸一个播放器 IV(终) —— Github Action 与组件发布

Reference

Alamofire
Kingfisher
VIMediaCache

License

ZonPlayer is available under the MIT license. See the LICENSE file for more info.