I'm using an image's properties to set the boundary for a MediaPlayer. That app crashes with the error below on the line: requireContext().assets.openFd(imagename)
Any thoughts?
player = MediaPlayer().apply {
requireContext().assets.openFd(imagename)
.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
)
}
FATAL EXCEPTION: main Process: io.github.sceneview.sample.araugmentedimage, PID: 2250 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) Caused by: java.io.FileNotFoundException: qrcode at android.content.res.AssetManager.nativeOpenAssetFd(Native Method) at android.content.res.AssetManager.openFd(AssetManager.java:1011) at io.github.sceneview.sample.araugmentedimage.MainFragment$onViewCreated$1$2.invoke(MainFragment.kt:77) at io.github.sceneview.sample.araugmentedimage.MainFragment$onViewCreated$1$2.invoke(MainFragment.kt:59) at io.github.sceneview.ar.ARSceneView.onSessionUpdated(ARSceneView.kt:324) at io.github.sceneview.ar.ARSceneView.onFrame(ARSceneView.kt:278) at io.github.sceneview.SceneView$frameCallback$1.doFrame(SceneView.kt:295) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1687) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1698) at android.view.Choreographer.doCallbacks(Choreographer.java:1153) at android.view.Choreographer.doFrame(Choreographer.java:1069) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1646) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:230) at android.os.Looper.loop(Looper.java:319) at android.app.ActivityThread.main(ActivityThread.java:8919) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Obviously you tried to open a file called "qrcode" using AssetManager, but it was not found. Check if this file is in your project or if it is in the correct path.