Show some placeholder until video loads in immersive view Vision OS

I am playing immersive video as shown in picture but it displays black screen until videos get loaded

and here is when video gets loaded

here is code snippet

struct ImmersiveMeditationPlayerView: View {
    @Environment(\.dismissImmersiveSpace) private var dismissImmersiveSpace
    @Environment(\.openWindow) private var openWindow
    let player = AVPlayer()
    
    
    init() {
        Logger.shared.log(message: "IMERSIVE VIEW INSIDE")
    }
    
    var body: some View {
        VStack {
            RealityView { content, attachments in
                            //Create Entity for the video
                            let videoEntity = Entity()
                            let url = URL(string: "https://videoc2CIarRqKp")!
                            let asset = AVURLAsset(url: url)
                            let playerItem = AVPlayerItem(asset: asset)
                           
                             //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()
            }
        attachments: {
            Attachment(id: "myMeditationBuilderView") {
               
            }
        }
        }

Hello,

Try listening for changes to your player item's status, until it is "readyToPlay", you could display your placeholder.

@gchiste I have tried to do so but can you share some code to add loading animation inside Reality View until videos gets played

Show some placeholder until video loads in immersive view Vision OS
 
 
Q