简体   繁体   English

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

[英]AVPlayer runs on simulator but not real device

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. 我正在使用系统WiFi热点将网络连接到设备。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AVPlayer导致模拟器崩溃,但在设备上运行正常 - AVPlayer causes Simulator to crash but runs fine on device AVPlayer在模拟器上运行,但不在设备上运行 - AVPlayer Works on Simulator, but not on device JSONDecoder 在模拟器上运行良好时无法在真实设备上解码 - JSONDecoder can't decode on real device when it runs fine on simulator AVPlayer + MPNowPlayingInfoCenter可在模拟器上运行,但不能在设备上运行 - AVPlayer + MPNowPlayingInfoCenter works on simulator but not on device avplayer在模拟器上而不是在设备上播放视频吗? - avplayer plays video on simulator not on device? 应用程序在模拟器上运行,而不在设备上运行 - App runs on Simulator, not on device 在模拟器上运行,但不在设备上运行 - Runs on Simulator but not on Device 使用AVPlayer的黑屏(在模拟器和设备中) - Black screen using AVPlayer (both in simulator and in device) 模拟器上的 AVPlayer 可访问的 tmp 视频文件,但不能访问设备 - tmp video file accessible to AVPlayer on simulator but not device 当我在模拟器上运行此代码时,它可以完美运行,但是在真实设备上崩溃? - When I run this code on a simulator it runs perfectly, however it crashes on a real device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM