如何在Swift中加载本地iPhone视频?

问题描述 投票:-1回答:2

文件的url路径是//// var / mobile / Containers / Data / Application / <> / Documents / IMG_2792.MP4

 func playVideo(videoURL: String){
    if let video_URL = documentsUrl.appendingPathComponent(videoURL) as? URL{
        let player = AVPlayer(url: video_URL)
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = self.vid_player!.bounds
       self.vid_player?.layer.addSublayer(playerLayer)
        player.play()
    }
}
ios swift xcode avplayer
2个回答
0
投票

您是否尝试将视频文件放入捆绑资源中并从中获取视频?


0
投票

尝试一下:使用fileURLWithPath

© www.soinside.com 2019 - 2024. All rights reserved.