In my application, I want to play a local video on my real device. I am using my system WiFi hotspot to connect the network to my device.
This code runs on the simulator perfectly, but not on a real device.
import UIKit
import AVKit
import AVFoundation
class SafaribroserViewController: UIViewController {
var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func hsdgfsf(_ sender: Any) {
let fileURL = NSURL.init(fileURLWithPath: "/Volumes/E/adam/small.mp4")
playerView = AVPlayer(url: fileURL as URL)
playerViewController.player = playerView
present(playerViewController,animated:true) {
self.playerViewController.player?.play()
}
}
}
May this will help you.
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
var player = AVPlayer()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
playVideo()
}
func playVideo() {
let path = Bundle.main.path(forResource: "myvideo", ofType:"m4v")
let player = AVPlayer(url: URL(fileURLWithPath: path))
let playerController = AVPlayerViewController()
playerController.player = player
present(playerController, animated: true) {
player.play()
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.