// Get the video URL
//Create Entity for the video
let videoEntity = Entity()
//Search for video in paths
guard let url = Bundle.main.url(forResource: "harmandir-sahib-sarovar", 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)
//set the actionAtItemEnd property to .none
player.actionAtItemEnd = .none
//subscribe to the notification and seek back to start
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { _ in
player.seek(to: CMTime.zero)
player.play()
}
player.play()
}
.contentShape(Rectangle())
.onTapGesture {
Task {
openWindow(id: "Video")
}
}
}
}
}
I did create a WindowGroup of that id Video to open a window with a back button. But unfortunately I have tried loads of methods especially with the .onTapGesture and when I try to tap anywhere on the screen in the VisionOS simulator but it still would not open the window. What I really want is to enable tap gestures in the simulator so that it can open the window by a single touch anywhere on the 360 panorama video (reality view).
I do not know what I have been doing wrong. I really need some help. Thank you.