iOS开发-阿里云播放器(Swift + SwiftUI / UIKit)

SDK配置

按照阿里文档配置

阿里云播放器SDK

基于阿里云播放器实现RTS拉流

简单的播放器

配置阿里播放器
import SwiftUI
import AliyunPlayer

let asd = UIView()

class AliPlayerManger: NSObject {
    
    // 初始化证书
    let a = AliPrivateService()

    // 播放管理器
    var player: AliPlayer?
    
    // 初始化播放器
    override init() {
        super.init()
        if player == nil {
            player = AliPlayer()
            // 显示播放器视图
            player?.playerView = asd
        }
    }
    
    

}

extension AliPlayerManger {
    
    // 播放本地视频
    func playLocalVideo(resource: String) {
        guard let urlString = Bundle.main.path(forResource: resource, ofType: "mp4") else { return }
        let urlSource = AVPUrlSource()
        urlSource.url(with: urlString)
        self.player?.setUrlSource(urlSource)
        self.player?.prepare()
        self.player?.start()
    }
    
    // 播放视频
    func playVideo(urlString: String){
        let urlSource = AVPUrlSource()
        urlSource.url(with: urlString)
        self.player?.setUrlSource(urlSource)
        self.player?.prepare()
        self.player?.start()
    }
    
}
swiftUI 桥接 UIKit
// swiftUI 桥接 UIKit 使用阿里云播放器
struct VideoView: UIViewRepresentable {
    
    let url: String
    
    func makeUIView(context: Context) -> UIView {
        let view = UIView()
        
        asd.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 300)
        
        view.addSubview(asd)

        return view
    }
    
    func updateUIView(_ uiView: UIView, context: Context) {
        ali.playVideo(urlString: url)
    }
}

使用
VideoView(url: "https://stream7.iqilu.com/10339/upload_transcode/202002/09/20200209105011F0zPoYzHry.mp4")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值