7

I have a default .mp4 file that I want to view using ExoPlayer (on Android). I use this small video:

http://techslides.com/demos/sample-videos/small.mp4

In the App I get a base64 string that is the video. When I paste in the above video in this site:

https://base64.guru/converter/encode/video

It shows the same Base64 values as what is being received in the App, however the below error is thrown.

player.playFromBytes(currentVideoBase64?.toByteArray()!!)

override fun playFromBytes(byteArray: ByteArray) {
    val mediaSource = createMediaSourceFromByteArray(byteArray)
    exoPlayer.prepare(mediaSource)
    exoPlayer.playWhenReady = true
}

private fun createMediaSourceFromByteArray(data: ByteArray): MediaSource {
    val byteArrayDataSource = ByteArrayDataSource(data)
    val factory = DataSource.Factory { byteArrayDataSource }
    val mediaSource = ProgressiveMediaSource.Factory(factory, DefaultExtractorsFactory())
            .createMediaSource(Uri.EMPTY)

    return Objects.requireNonNull(mediaSource, "MediaSource cannot be null")
}

Error Message:

2019-09-18 18:09:59.970 18009-18743/ 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, Ac4Extractor) could read the stream.
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractorHolder.selectExtractor(ProgressiveMediaPeriod.java:1059)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:947)
        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:764)

UPDATE: using Base64.getDecoder().decode(currentVideoBase64) it works but only for Android O & higher.

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

0 Answers0