我的 Vimeo 帐户中有 360 度视频,我正在寻找一种方法在我的 VisionOS 应用程序中渲染它。 我尝试使用此代码以 360 度模式播放视频,但不幸的是,visionOS 开发不支持
AVKit
。
//Create Entity for the video
let videoEntity = Entity()
//Search for video in paths
guard let url = Bundle.main.url(forResource: "example", 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)
player.play()
}
是否有解决方法可以在visionOS或任何处理它的SDK中播放360度视频?
guard let url = Bundle.main.url(forResource: "example", withExtension: "mp4") else {fatalError("Video was not found!")}
适用于项目文件夹中的文件。
您需要来自 Vimeo 的直接链接
https://help.vimeo.com/hc/en-us/articles/12426150952593-Direct-links-to-video-files
您可以在
VideoMaterial
中下载/播放它