Created
July 17, 2020 21:40
-
-
Save huxaiphaer/268b94a0e7959822fa679a7523701187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun playbackArVideo(augmentedImage: AugmentedImage) { | |
Log.d(TAG, "playbackVideo = ${augmentedImage.name}") | |
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 | |
) | |
// Update the material parameters | |
videoRenderable.material.setFloat2( | |
MATERIAL_IMAGE_SIZE, | |
imageSize.width(), | |
imageSize.height() | |
) | |
videoRenderable.material.setFloat2(MATERIAL_VIDEO_SIZE, videoWidth, videoHeight) | |
videoRenderable.material.setBoolean(MATERIAL_VIDEO_CROP, VIDEO_CROP_ENABLED) | |
mediaPlayer.reset() | |
mediaPlayer.setDataSource(descriptor) | |
}.also { | |
mediaPlayer.isLooping = true | |
mediaPlayer.prepare() | |
mediaPlayer.start() | |
} | |
videoAnchorNode.anchor?.detach() | |
videoAnchorNode.anchor = augmentedImage.createAnchor(augmentedImage.centerPose) | |
activeAugmentedImage = augmentedImage | |
externalTexture.surfaceTexture.setOnFrameAvailableListener { | |
it.setOnFrameAvailableListener(null) | |
fadeInVideo() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whats this @Tyqjshdidbhdid L130108001?