AVPlayer播放远程视频

//
//  ViewController.swift
//  AVPlayer播放远程视频
//
//  Created by lujun on 2022/1/30.
//

import UIKit
import AVKit
class ViewController: UIViewController {
    lazy var player: AVPlayer = {
        let url = URL(string: "https://722-4.vod.tv.itc.cn/sohu/v1/TmwBq6IsWByHytyDTSsO8TCDzT8bgEd4ym82ZhAX8FXUyYbSoO27fSx.mp4?k=RoZi7r&p=j9lvzSwUqpPiqpsGqmX3qpv30SoGqLP3hRYRzSPWXZxIWhoGgY27oVfS0pviNF2CfM0&r=TUldziJCtpCmhWB3tSCGhWlvsmCioLPWtWaizY&q=OpCmhW7IRYodRD6svmfCyY2sWhvHfOvHfhvO5G6OfOo2ZDvtWOAsRhNsvm4cWJvXY&nid=722")
        let player = AVPlayer(url: url!)
        return player
    }()
    var layer: AVPlayerLayer?
    override func viewDidLoad() {
        super.viewDidLoad()
        layer = AVPlayerLayer(player: player)
        view.layer.addSublayer(layer!)
        
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        player.play()
       
    }
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        layer?.frame = view.layer.bounds
    }
}


上一篇:初探numpy


下一篇:Swift5 AVPlayerViewController的基本使用