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
- Create a curved surface in a 3D modeling program and convert it to USDZ afterwards
- Make a USDA Scene with the curved surface
- 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 :)