gpt4 book ai didi

ios - AVPlayer 在模拟器上运行但不是真实设备

转载 作者:行者123 更新时间:2023-11-28 08:03:33 25 4
gpt4 key购买 nike

在我的应用程序中,我想在我的真实设备上播放本地视频。我正在使用我的系统 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()
}
}
}

最佳答案

希望这对你有帮助。

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

关于ios - AVPlayer 在模拟器上运行但不是真实设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45859548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com