show loading animation in immersive view until av player loads videos from a url also is there any way to pass dynamic url to this view since it is places inside app struct which gets initialised when app gets loads into memory
struct ImmersiveMeditationPlayerView: View {
@Environment(\.dismissImmersiveSpace) private var dismissImmersiveSpace
@Environment(\.openWindow) private var openWindow
let player = AVPlayer()
var body: some View {
VStack {
RealityView { content, attachments in
//Create Entity for the video
let videoEntity = Entity()
let url = URL(string: "https://somevideo/135-87.m3u8")!
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()
}
}
You can do it via
and making use of the
updatefor adding/removing theProgressViewandattachmentsto define theProgressView.I defined the "Helper" as follows.
And the rest of the code you'll need is just some convenience code.