That is my code, I still have the pink material for iOS 18. While on iOS 17 is working fine.
Any advice?
// Create Video Screen
private func createVideoScreen(width: Float, height: Float, url: URL, uuid: UUID) -> ModelEntity {
let screenMesh = MeshResource.generatePlane(width: width, height: height)
let videoItem = createVideoItem(with: url)
let videoMaterial = createVideoMaterial(with: videoItem, uuid: uuid)
let videoScreenModel = ModelEntity(mesh: screenMesh, materials: [videoMaterial])
return videoScreenModel
}
// Create Video Item
private func createVideoItem(with url: URL) -> AVPlayerItem {
let asset = AVURLAsset(url: url)
let videoItem = AVPlayerItem(asset: asset)
return videoItem
}
// Create Video Material
private func createVideoMaterial(with videoItem: AVPlayerItem, uuid: UUID) -> VideoMaterial {
let player = AVPlayer()
player.actionAtItemEnd = .none
let videoMaterial = VideoMaterial(avPlayer: player)
player.replaceCurrentItem(with: videoItem)
player.play()
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { _ in
player.seek(to: .zero)
player.play()
}
videoPlayers[uuid] = player
return videoMaterial
}
// Place Video Screen
private func placeVideoScreen(videoScreen: ModelEntity, imageAnchor: ARImageAnchor, uuid: UUID) {
guard let arView = arView else { return }
let imageAnchorEntity = AnchorEntity(anchor: imageAnchor)
let rotationAngle = simd_quatf(angle: GLKMathDegreesToRadians(-90), axis: SIMD3(x: 1, y: 0, z: 0))
videoScreen.setOrientation(rotationAngle, relativeTo: imageAnchorEntity)
imageAnchorEntity.addChild(videoScreen)
arView.scene.addAnchor(imageAnchorEntity)
activeAnchors[uuid] = imageAnchorEntity
}
Topic:
Graphics & Games
SubTopic:
RealityKit
Tags: