Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 360 videos in visionOS

I have 360 videos in my Vimeo account and I am looking for a way to render it in my visionOS App. I tried using this code to play video in 360 mode but unfortunately AVKit isn't supported in visionOS development.

   //Create Entity for the video
    let videoEntity = Entity()

    //Search for video in paths
    guard let url = Bundle.main.url(forResource: "example", withExtension: "mp4") else {fatalError("Video was not found!")}
    
    //create a simple AVPlayer
    let asset = AVURLAsset(url: url)
    let playerItem = AVPlayerItem(asset: asset)
    let player = AVPlayer()

    //create a videoMaterial
    let material = VideoMaterial(avPlayer: player)

    //Made a Sphere with the videoEntity and asign the videoMaterial to it
    videoEntity.components.set(ModelComponent(mesh: .generateSphere(radius: 1E3), materials: [material]))

    //adjust the properties of the videoEntity(Sphere) if needed
    videoEntity.scale = .init(x: 1, y: 1, z: -1)
    videoEntity.transform.translation += SIMD3<Float>(0.0, 10.0, 0.0)

    let angle = Angle.degrees(90)
    let rotation = simd_quatf(angle: Float(angle.radians), axis: .init(x: 0, y: 0, z: 0))

    videoEntity.transform.rotation = rotation

    //add VideoEntity to realityView
    content.add(videoEntity)
    
    //start the VideoPlayer
    player.replaceCurrentItem(with: playerItem)
    player.play()

}

Is there a workaround to play 360 videos in visionOS or any SDK that handles it?

like image 240
CharlyKeleb Avatar asked Dec 01 '25 16:12

CharlyKeleb


1 Answers

guard let url = Bundle.main.url(forResource: "example", withExtension: "mp4") else {fatalError("Video was not found!")}

Is for files in your project folder.

You need a direct link from Vimeo

https://help.vimeo.com/hc/en-us/articles/12426150952593-Direct-links-to-video-files

The you can download/play it in a VideoMaterial

like image 72
lorem ipsum Avatar answered Dec 03 '25 08:12

lorem ipsum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!