Automattic/stories-android

Crash in optimize media when getting video duration for analytics

mzorz opened this issue · 2 comments

mzorz commented

First reported by @jd-alexander in #623 (review)

Copying the text here:

  1. This crash occurred when I added a video. I suspect that there might be something wrong with the emulator why it happened but I am not sure. Once the video frame was selected and the progress bar started spinning the app would crash with the error below.
 java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        at android.media.MediaMetadataRetriever.setDataSource(Native Method)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:244)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:332)
        at org.wordpress.android.util.VideoUtils.getVideoDurationMS(VideoUtils.java:26)
        at org.wordpress.android.util.VideoUtils.getVideoDurationMS(VideoUtils.java:16)
        at org.wordpress.android.util.analytics.AnalyticsUtils.getMediaProperties(AnalyticsUtils.java:605)
        at org.wordpress.android.ui.posts.editor.EditorTracker.trackAddMediaFromDevice(EditorTracker.kt:39)
        at org.wordpress.android.ui.posts.editor.media.OptimizeMediaUseCase.optimizeMedia(OptimizeMediaUseCase.kt:61)
        at org.wordpress.android.ui.posts.editor.media.OptimizeMediaUseCase.access$optimizeMedia(OptimizeMediaUseCase.kt:21)
        at org.wordpress.android.ui.posts.editor.media.OptimizeMediaUseCase$optimizeMediaIfSupportedAsync$2$invokeSuspend$$inlined$map$lambda$1.invokeSuspend(OptimizeMediaUseCase.kt:34)

mzorz commented

Interesting, I found a video on my emulator that produces the same result, but while it doesn't crash on mobile Gutenberg, it throws the same Exception (which apparently is logged but eaten):

2020-12-04 18:55:36.373 6053-6053/org.wordpress.android I/WordPress-MEDIA: MediaUploadHandler > Upload completed - localId=107 title=file_example_WMV_1920_9_3MB-2.wmv
2020-12-04 18:55:36.392 6053-6053/org.wordpress.android E/WordPress-MEDIA: Can't read duration of the video due to a Runtime Exception happened setting the datasource
    java.lang.RuntimeException: setDataSource failed: status = 0x80000000
        at android.media.MediaMetadataRetriever.setDataSource(Native Method)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:75)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:163)
        at org.wordpress.android.util.VideoUtils.getVideoDurationMS(VideoUtils.java:26)
        at org.wordpress.android.util.VideoUtils.getVideoDurationMS(VideoUtils.java:16)
        at org.wordpress.android.util.analytics.AnalyticsUtils.getMediaProperties(AnalyticsUtils.java:605)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.trackUploadMediaEvents(MediaUploadHandler.java:381)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.handleOnMediaUploadedSuccess(MediaUploadHandler.java:181)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.onMediaUploaded(MediaUploadHandler.java:366)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:507)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:501)
        at org.greenrobot.eventbus.HandlerPoster.handleMessage(HandlerPoster.java:67)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-12-04 18:55:36.400 6053-6053/org.wordpress.android I/WordPress-STATS: 🔵 Tracked: media_service_upload_response_ok, Properties: {"ext":"wmv","age_ms":14374,"bytes":9338829,"mime":"video\/x-ms-wmv","duration_secs":0}
2020-12-04 18:55:36.409 6053-6053/org.wordpress.android E/WordPress-MEDIA: Can't read duration of the video due to a Runtime Exception happened setting the datasource
    java.lang.RuntimeException: setDataSource failed: status = 0x80000000
        at android.media.MediaMetadataRetriever.setDataSource(Native Method)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:75)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:163)
        at org.wordpress.android.util.VideoUtils.getVideoDurationMS(VideoUtils.java:26)
        at org.wordpress.android.util.VideoUtils.getVideoDurationMS(VideoUtils.java:16)
        at org.wordpress.android.util.analytics.AnalyticsUtils.getMediaProperties(AnalyticsUtils.java:605)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.trackUploadMediaEvents(MediaUploadHandler.java:381)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.completeUploadWithId(MediaUploadHandler.java:224)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.handleOnMediaUploadedSuccess(MediaUploadHandler.java:183)
        at org.wordpress.android.ui.uploads.MediaUploadHandler.onMediaUploaded(MediaUploadHandler.java:366)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:507)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:501)
        at org.greenrobot.eventbus.HandlerPoster.handleMessage(HandlerPoster.java:67)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-12-04 18:55:36.418 6053-6053/org.wordpress.android I/WordPress-STATS: 🔵 Tracked: media_service_upload_started, Properties: {"ext":"wmv","age_ms":14400,"bytes":9338829,"mime":"video\/x-ms-wmv","duration_secs":0}
2020-12-04 18:55:36.418 6053-6053/org.wordpress.android W/WordPress-MEDIA: MediaUploadHandler > No more media items to upload. Skipping this request.
2020-12-04 18:55:36.419 6053-6053/org.wordpress.android I/WordPress-MEDIA: MediaUploadHandler > Completed
2020-12-04 18:55:36.419 6053-6053/org.wordpress.android I/WordPress-MAIN: UploadService > Processing completed media with id 107 and local post id 93
2020-12-04 18:55:36.457 6053-6053/org.wordpress.android I/ExoPlayerImpl: Init a245acf [ExoPlayerLib/2.9.3] [generic_x86, Android SDK built for x86, Google, 29]
2020-12-04 18:55:36.541 6053-6416/org.wordpress.android E/ExoPlayerImplInternal: Source error.
    com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor) could read the stream.
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:973)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:891)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
2020-12-04 18:55:36.802 1776-6419/? E/ResolverController: No valid NAT64 prefix (101, <unspecified>/0)
2020-12-04 18:55:37.180 6053-6416/org.wordpress.android E/ExoPlayerImplInternal: Source error.
    com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor) could read the stream.
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:973)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:891)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
2020-12-04 18:55:38.668 2045-5105/system_process W/AppOps: Noting op not finished: uid 10098 pkg com.google.android.gms code 41 time=1607118933649 duration=0
2020-12-04 18:55:40.788 2694-22635/com.google.android.gms.persistent E/WakeLock: GCM_HB_ALARM release without a matched acquire!

Here we can see the exception happens 2 times: one for the analytics tracking that tries to establish the duration of the video in miliseconds by using setDataSource on the media metadata extractor, and the last one which is by ExoPlayer which is used in the React Native video player component.

I'll look further into how Stories work so to be able to catch the Exception and continue the same way as it goes for Gutenberg (given we don't really care if we couldn't track the duration of a video)

mzorz commented

I haven't been able to reproduce. Checked Sentry and a search for setDataSource only throws these 2 results:

Last time this one was seen was on version 16.3 of WPAndroid, when we changed the mode to copy media from external URLs, which I think helps to eliminate the problem given it should mostly be fine to open local urls in setDataSource().

Closing this one then.