Skip to content

Instantly share code, notes, and snippets.

@shliama
Last active October 29, 2019 15:21
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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment