AVPlayer在模拟器上运行,但不在真实设备

时间:2017-08-24 10:44:52

标签: ios swift video

在我的应用程序中,我想在我的真实设备上播放本地视频。我正在使用我的系统WiFi热点将网络连接到我的设备。

此代码在模拟器上完美运行,但不在真实设备上运行。

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()
            }
        }
 }

1 个答案:

答案 0 :(得分:0)

愿这对你有所帮助。

  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()
    }
  }
}