admin管理员组

文章数量:1287622

Does anyone know how to access video and json files in the new versions of swift playgrounds?

I'm trying to access throught Bundle url or path, but it's not working.

My files are inside Resources folder.

I tried this way using path:

if let path = Bundle.main.path(forResource: "helloASL", ofType: "mp4") {
                let url = URL.init(filePath: path)
                
                let item = AVPlayerItem(url: url)
                
                VideoPlayer(player: AVPlayer(playerItem: item))
            } else {
                Text("Video not found")
            }

this using url:

if let url = Bundle.main.url(forResource: "helloASL", withExtension: "mp4") {
                
                VideoPlayer(player: AVPlayer(url: url))
                                    .frame(height: 300) // Set the desired frame size
                                    .onAppear {
                                        AVPlayer(url: url).play()
                                    }
            } else {
                Text("Video not found")
            }

本文标签: swiftuiHow to access Bundle in swift PlaygroundStack Overflow