Playing a video file from a server in Swift

前端 未结 4 1781
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 12:42

I\'m trying to play a video from a server using Swift.

I have imported MediaPlayer framework, here is my code:

import UIKit
import M         


        
4条回答
  •  [愿得一人]
    2020-12-07 12:58

    Import the libraries:

    import AVKit
    import AVFoundation
    import MediaPlayer
    import AudioToolbox   
    

    Set delegaete like this

    AVPlayerViewControllerDelegate
    

    Wrtie pretty code where you want to play like button action:

    let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        let player = AVPlayer(url: videoURL!)
        let playervc = AVPlayerViewController()
        playervc.delegate = self
        playervc.player = player
        self.present(playervc, animated: true) {
            playervc.player!.play()
        }
    

    100% working and test

提交回复
热议问题