how to stream video from a url in swift code example

Example 1: how can i play video with url in a view in swift

let url = URL(string:myURL)

player = AVPlayer(url: url!)

avpController.player = player

avpController.view.frame.size.height = videoView.frame.size.height

avpController.view.frame.size.width = videoView.frame.size.width

self.videoView.addSubview(avpController.view)

Example 2: swift play video from url

import AVKit
import AVFoundation

class VideoController: UIViewController

override func viewDidLoad(){
  	guard let videoURL = URL(string: "VideoURL") else {
      	return
    }
    let player = AVPlayer(url: videoURL)
    let playerViewController = AVPlayerViewController()
    playerViewController.player = player
    self.present(playerViewController, animated: true) {
      playerViewController.player?.play()
    }


}