0

I'm building a Flutter app that takes a list of video clip URL's from Firebase, downloads them to storage and stores the file paths. Afterwards the user can go through the list of video paths and play the video clips that has been downloaded. This is done with the Flutter video_player.

ISSUE

It should be pretty straight forward, but for some reason, some of the video clips can't be loaded and played by the VideoPlayerController. All the video clips are in the exact same format, having been rendered, compressed and uploaded the same way.

Each video clip is downloaded to storage like this:

var dir = await getApplicationDocumentsDirectory();
String filePath = "video/$index.mp4";
String fullPath = dir.path + filePath;
Response videoResponse = await dio.download(videoUrl, fullPath);

if (videoResponse.statusCode == 200) {
      videoPath = fullPath;
      print("Downloaded: $filePath");
    } else {
      print("Download error")
    }

The videoPathwill then be stored in a list and sent the screen containing the video player.

Inside the video player screen, that is how it will load the video clips from file:

_controller = VideoPlayerController.file(
    new File(videos[index].videoPath));

_initPlayerFuture = _controller.initialize();

This code will use index to change between each file in the list.

When I run this, about 50% of the clips will load and play perfectly, while the others will return the following error on log:

E/ExoPlayerImplInternal(27253): Source error.
E/ExoPlayerImplInternal(27253): 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.
E/ExoPlayerImplInternal(27253):     at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:973)
E/ExoPlayerImplInternal(27253):     at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:891)
E/ExoPlayerImplInternal(27253):     at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
E/ExoPlayerImplInternal(27253):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal(27253):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal(27253):     at java.lang.Thread.run(Thread.java:764)

I seem to have isolated the problem to the way I save the videoclips to storage (See NOTES), but that doesn't explain why some clips work and others don't.

Does anybody know what might be going on, and how to fix it? Or have anybody had the same issue, and might have some experience to share?

Thanks in advance!

NOTES

  • Whenever I skip the download-to-storage-process, and just use VideoPlayerController.network(videos[index].videoUrl) all the videos will play without any issues. It's important however, that all the videoclips are downloaded at the same time in the beginning.

  • It's the same clips each time that either works or not, and it doesn't matter what position they come in.

  • I've check up on all the paths getting sent to the VideoPlayerController, and they're all correctly stored and shared with the video player.

  • Might be related to this post: Flutter video_player not playing video saved to application directory

4

1 回答 1

0

我弄清楚了这个问题。在下载过程中,我正在为每个视频剪辑下载一些元数据,其中包括其他媒体文件。出于某种原因,我为其中一些文件指定了与视频剪辑相同的保存文件路径。他们只是覆盖了每一个。由于只有部分视频剪辑在元数据中包含此媒体文件,这就是导致错误仅显示在某些剪辑上的原因。

于 2020-09-18T13:41:43.647 回答