YHPlayer

An easy-to-use video player based on swift language

CI Status Version License Platform

Features

  • Plays local media or streams remote media over HTTP
  • Custom UI control layer screen
  • Support screen rotation
  • Simple API
  • Clear delegate method
  • Audio Default is muted
  • AutoPlay Default is False

Requirements

iOS 11.0 or later xcode 11.0 or later

Installation

YHPlayer is available through CocoaPods. To install it, simply add the following line to your Podfile:

target 'YourProductName' do
    pod 'YHPlayer'
    ...

Install pods

$ pod install

And then import import YHPlayer where you use.

How to use

1.create YHPlayer
        let playView = YHPlayer(frame: .zero)
        playView.delegate = self

2.create YHPlayerItemConfig
        let itemConfig = YHPlayerItemConfig(videoURL: videoURL1,
                                            isMuted: false,
                                            isAutoPlay: false,
                                            thumbImg: .init(named: "thumbimg"))

3.set itemConfig to player
        playView.config(with: itemConfig)

4.custome your controlPanel
        playView.addCustomeControl(controlView)

YHPlayerDelegate

public protocol YHPlayerDelegate: NSObjectProtocol {
    /// 更新播放进度
    func yhPlayer(_ player: YHPlayer, notifyCurrentProgress progress: TimeInterval)
    
    /// 更新缓冲进度
    func yhPlayer(_ player: YHPlayer, notifyBufferProgress progress: TimeInterval)
    
    /// 准备播放
    func yhPlayerReadyToPlay(_ player: YHPlayer)
    
    /// 失败播放
    func yhPlayerFailedToPlay(_ player: YHPlayer, error: YHPlayer.Error)
    
    /// 播放完毕
    func yhPlayerDidEndPlaying(_ player: YHPlayer)
    
    /// 播放中断(来电话等优先级高的)
    func yhPlayerInterruptioned(_ player: YHPlayer, interruptionType type: YHPlayer.InterruptionType)
    
    /// 状态发生改变
    func yhPlayerStatusChanged(_ player: YHPlayer, status: YHPlayer.PlayStatus)
}

Run result

Author

YEHAN, [email protected]

License

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

GitHub

View Github