iOS視頻播放器BSPlayer使用

一個(gè)由AVPlayer開(kāi)發(fā)的視頻播放器,支持旋轉(zhuǎn)全屏,速度控制,調(diào)節(jié)播放進(jìn)度,還可以自己自定義UI。


landscape.jpeg
portrait.jpeg

使用

  1. 基本使用
let player = BSVideoPlayer(
        url: urls.last!,
        frame: CGRect.init(x: 0, y: UIApplication.shared.statusBarFrame.height, width: view.frame.width, height: (9.0/16.0)*view.frame.width)
    )
view.addSubview(player)
  1. 旋轉(zhuǎn)
是否自動(dòng)旋轉(zhuǎn)
override var shouldAutorotate: Bool {
    if player == nil {
        return true
    }
    return player.shouldAutorotate
}

重寫(xiě)controller的tanstion方法

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    player.viewWillTransition(to: size, with: coordinator)
}
  1. 狀態(tài)欄隱藏控制
override var prefersStatusBarHidden: Bool {
    if player == nil {
        return false
    }
    if !player.isPortrait {
        return true
    }
    return true
}
  1. 播放器的一些代理方法
// 點(diǎn)擊返回按鈕
func playerViewClickBack(playerView: BSVideoPlayer) {}

// 播放器將要旋轉(zhuǎn)
func playerView(playerView: BSVideoPlayer, shouldRotateTo orientation: UIInterfaceOrientation) {}

// 播放器已經(jīng)完成旋轉(zhuǎn)
func playerView(playerView: BSVideoPlayer, didRotateTo orienttation: UIInterfaceOrientation) {}

// 控制視圖將要隱藏
func playerView(playerView: BSVideoPlayer, controllViewWillFade state: Int) {}

// 控制視圖已經(jīng)隱藏
func playerView(playerView: BSVideoPlayer, controllViewDidFade state: Int) {}

詳細(xì)使用請(qǐng)查看項(xiàng)目中的代碼

安裝

Cocoapods

  1. 在Podfile文件中添加pod 'BSPlayer'
  2. 運(yùn)行 pod install 或者 pod update
  3. 導(dǎo)入 import BSPlayer

手動(dòng)

  1. 下載項(xiàng)目
  2. 直接把Class文件夾拉到項(xiàng)目中

BSPlayer

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容