How to play video in full immersive space in vision Pro

I am trying to implement a feature to play video in full immersive space but unable to achieve desired results. When I run app in full immersive space, it shows video in center of screen/window. See screenshot below.

Can you please guide/refer me how to implement a behaviour to play video in full immersive space, just like below image

Regards, Yasir Khan

Answered by PatrickDevX in 763066022
  1. Create a curved surface in a 3D modeling program and convert it to USDZ afterwards
  2. Make a USDA Scene with the curved surface
  3. Make an Entity with the scene and assign the VideoPlayerComponent to it.
        RealityView() { content in
            //load your scene with the curved surface
            if let entity = try? await Entity(named: "EntityName", in: realityKitContentBundle) {

                //check if Video exists and is accessible
                guard let url = Bundle.main.url(forResource: "videoname", withExtension: "mp4") else {fatalError("Video was not found!")}

                let asset = AVURLAsset(url: url)

                let playerItem = AVPlayerItem(asset: asset)

                let player = AVPlayer()

                //add VideoPlayerComponent to entity
                entity.components[VideoPlayerComponent.self] = .init(avPlayer: player)

                //Adjust the scale of the entity
                entity.scale *= 0.5

                // you can also adjust the position of your entity here in code if needed
                // entity.position = SIMD3(x: , y: , z: )

                content.add(entity)

                player.replaceCurrentItem(with: playerItem)
                player.play()

            }else {
                print("Entity with the given name was not found!")
            }

        }
    }

Hope I could help you :)

Accepted Answer
  1. Create a curved surface in a 3D modeling program and convert it to USDZ afterwards
  2. Make a USDA Scene with the curved surface
  3. Make an Entity with the scene and assign the VideoPlayerComponent to it.
        RealityView() { content in
            //load your scene with the curved surface
            if let entity = try? await Entity(named: "EntityName", in: realityKitContentBundle) {

                //check if Video exists and is accessible
                guard let url = Bundle.main.url(forResource: "videoname", withExtension: "mp4") else {fatalError("Video was not found!")}

                let asset = AVURLAsset(url: url)

                let playerItem = AVPlayerItem(asset: asset)

                let player = AVPlayer()

                //add VideoPlayerComponent to entity
                entity.components[VideoPlayerComponent.self] = .init(avPlayer: player)

                //Adjust the scale of the entity
                entity.scale *= 0.5

                // you can also adjust the position of your entity here in code if needed
                // entity.position = SIMD3(x: , y: , z: )

                content.add(entity)

                player.replaceCurrentItem(with: playerItem)
                player.play()

            }else {
                print("Entity with the given name was not found!")
            }

        }
    }

Hope I could help you :)

@PatrickDevX I am trying to play video in full immersive space. I just gave an example of panorama. In actual, I want to video to cover full space just like panaroma/background image covers. The solution you suggested just add video as a component of entity.

How to play video in full immersive space in vision Pro
 
 
Q