requireContext().assets.openFd(augmentedImage.name) .use { descriptor -> val metadataRetriever = MediaMetadataRetriever() metadataRetriever.setDataSource( descriptor.fileDescriptor, descriptor.startOffset, descriptor.length ) val videoWidth = metadataRetriever.extractMetadata(METADATA_KEY_VIDEO_WIDTH).toFloatOrNull() ?: 0f val videoHeight = metadataRetriever.extractMetadata(METADATA_KEY_VIDEO_HEIGHT).toFloatOrNull() ?: 0f val videoRotation = metadataRetriever.extractMetadata(METADATA_KEY_VIDEO_ROTATION).toFloatOrNull() ?: 0f // Account for video rotation, so that scale logic math works properly val imageSize = RectF(0f, 0f, augmentedImage.extentX, augmentedImage.extentZ) .transform(rotationMatrix(videoRotation)) val videoScaleType = VideoScaleType.CenterCrop videoAnchorNode.setVideoProperties( videoWidth = videoWidth, videoHeight = videoHeight, videoRotation = videoRotation, imageWidth = imageSize.width(), imageHeight = imageSize.height(), videoScaleType = videoScaleType ) mediaPlayer.reset() mediaPlayer.setDataSource(descriptor) }.also { mediaPlayer.prepare() mediaPlayer.start() }