How can I add a button and manage its event in the immersive video playback view in SwiftUI?

When I play a video with immersive mode on an apple vision pro device, I want to add a close button to close the immersive video view play screen. How can I add a button and handle the event?

Hello,

There are several different ways you could add a button, the most straightforward way in this scenario would be to create an Attachment that holds a Button, and place it somewhere in your immersive space.

In response to the Button's action closure being called, you would close your immersive space using the dismissImmersiveSpace environment action.

How can I add a button and manage its event in the immersive video playback view in SwiftUI?
 
 
Q