Flutter插件:在Android方面使用exoplayer打开原始资源

时间:2019-08-12 16:51:30

标签: android flutter android-resources exoplayer flutter-plugin

我正在开发Flutter插件,需要使用ExoPlayer打开原始资源(视频)。实例化如下:

ExoPlayerFactory.newSimpleInstance(context).apply {
        DefaultDataSourceFactory(context, UserAgent(context).asString)
            .let(::ProgressiveMediaSourceFactory)
            .createMediaSource(RawResourceDataSource.buildRawResourceUri(resourceId))
            .apply(this::prepare)
            .apply { playWhenReady = true }
    }

提供的资源ID为R.raw.video,而在raw内的res目录中,我有一个video.mov文件。这段代码在纯本机项目和应用程序类型的flutter项目(我只是在其中显示一个ExoPlayer UI播放器支持的平台视图)中可以正常工作,但是当我尝试执行与Flutter应用程序完全相同的操作时,该代码不适用于Flutter插件项目已经描述过。

该如何解决?也许与外部模块内部的资源引用有关的问题?

这是ExoPlayer在准备过程中引发的错误:

  

E / LoadTask(6934):意外的异常加载流

     

E / LoadTask(6934):java.lang.ArrayIndexOutOfBoundsException:length = 16; regionStart = 0; regionLength = -298328891

     

E / LoadTask(6934):位于java.util.Arrays.checkOffsetAndCount(Arrays.java:135)

     

E / LoadTask(6934):位于libcore.io.IoBridge.read(IoBridge.java:496)

     

E / LoadTask(6934):位于java.io.FileInputStream.read(FileInputStream.java:307)

     

E / LoadTask(6934):com.google.android.exoplayer2.upstream.RawResourceDataSource.read(RawResourceDataSource.java:150)

     

E / LoadTask(6934):com.google.android.exoplayer2.upstream.DefaultDataSource.read(DefaultDataSource.java:262)

     

E / LoadTask(6934):com.google.android.exoplayer2.upstream.StatsDataSource.read(StatsDataSource.java:91)

     

E / LoadTask(6934):com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFromDataSource(DefaultExtractorInput.java:260)

     

E / LoadTask(6934):在com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFully(DefaultExtractorInput.java:72)

     

E / LoadTask(6934):在com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readAtomHeader(Mp4Extractor.java:275)

     

E / LoadTask(6934):在com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:183)

     

E / LoadTask(6934):com.google.android.exoplayer2.source.ProgressiveMediaPeriod $ ExtractingLoadable.load(ProgressiveMediaPeriod.java:954)

     

E / LoadTask(6934):com.google.android.exoplayer2.upstream.Loader $ LoadTask.run(Loader.java:381)

     

E / LoadTask(6934):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)   E / LoadTask(6934):位于java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641)

     

E / LoadTask(6934):位于java.lang.Thread.run(Thread.java:764)

     

E / ExoPlayerImplInternal(6934):源错误。

     

E / ExoPlayerImplInternal(6934):com.google.android.exoplayer2.upstream.Loader $ UnexpectedLoaderException:意外的ArrayIndexOutOfBoundsException:length = 16; regionStart = 0; regionLength = -298328891

     

E / ExoPlayerImplInternal(6934):在com.google.android.exoplayer2.upstream.Loader $ LoadTask.run(Loader.java:403)

     

E / ExoPlayerImplInternal(6934):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)

     

E / ExoPlayerImplInternal(6934):在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641)

     

E / ExoPlayerImplInternal(6934):在java.lang.Thread.run(Thread.java:764)

     

E / ExoPlayerImplInternal(6934):由以下原因引起:java.lang.ArrayIndexOutOfBoundsException:length = 16; regionStart = 0; regionLength = -298328891

     

E / ExoPlayerImplInternal(6934):在java.util.Arrays.checkOffsetAndCount(Arrays.java:135)

     

E / ExoPlayerImplInternal(6934):在libcore.io.IoBridge.read(IoBridge.java:496)

     

E / ExoPlayerImplInternal(6934):在java.io.FileInputStream.read(FileInputStream.java:307)

     

E / ExoPlayerImplInternal(6934):位于com.google.android.exoplayer2.upstream.RawResourceDataSource.read(RawResourceDataSource.java:150)

     

E / ExoPlayerImplInternal(6934):位于com.google.android.exoplayer2.upstream.DefaultDataSource.read(DefaultDataSource.java:262)

     

E / ExoPlayerImplInternal(6934):位于com.google.android.exoplayer2.upstream.StatsDataSource.read(StatsDataSource.java:91)

     

E / ExoPlayerImplInternal(6934):位于com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFromDataSource(DefaultExtractorInput.java:260)

     

E / ExoPlayerImplInternal(6934):位于com.google.android.exoplayer2.extractor.DefaultExtractorInput.readFully(DefaultExtractorInput.java:72)

     

E / ExoPlayerImplInternal(6934):在com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readAtomHeader(Mp4Extractor.java:275)

     

E / ExoPlayerImplInternal(6934):在com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:183)

     

E / ExoPlayerImplInternal(6934):在com.google.android.exoplayer2.source.ProgressiveMediaPeriod $ ExtractingLoadable.load(ProgressiveMediaPeriod.java:954)

     

E / ExoPlayerImplInternal(6934):在com.google.android.exoplayer2.upstream.Loader $ LoadTask.run(Loader.java:381)

     

E / ExoPlayerImplInternal(6934):...还有3个

0 个答案:

没有答案