skip to Main Content

I want to display a video stored locally on my device using the video player package in Flutter. the problem is that the app crashes when i try to load a video either from youtube using .network or locally using .file. When using .asset the player works perfectly.

class CustomVideoPlayer extends StatefulWidget {
  final List<Uint8List> receivedData;
  const CustomVideoPlayer(this.receivedData);

  @override
  State<CustomVideoPlayer> createState() => _CustomVideoPlayerState();
}

class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
  bool _isLoading = true;
  late VideoPlayerController _controller;
  @override
  void initState() {
    if (_isLoading) {
      final videoProcessed =
          Provider.of<VideoProcessed>(context, listen: false);
      videoProcessed.convertListToVideoFile().then((value) {
        print(videoProcessed.videoFile);
        _controller = VideoPlayerController.network(
            'https://www.youtube.com/watch?v=QC8iQqtG0hg');

        Future.delayed(
          Duration(seconds: 10),
          () {
            _controller.addListener(() {
              setState(() {});
            });
            _controller.setLooping(true);
            _controller.initialize().then((value) {
              setState(() {
                _isLoading = false;
              });
            });
            _controller.play();
          },
        );
      });
    }
    // TODO: implement initState
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final height = MediaQuery.of(context).size.height;
    final width = MediaQuery.of(context).size.width;
    return Container(
      height: height * 0.7497223250647908,
      width: width * 0.6573477447516109,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20),
      ),
      child: _isLoading
          ? Center(
              child: CircularProgressIndicator(),
            )
          : ClipRRect(
              borderRadius: BorderRadius.circular(20),
              child: _controller.value.isInitialized
                  ? AspectRatio(
                      aspectRatio: _controller.value.aspectRatio,
                      child: VideoPlayer(_controller))
                  : Container(
                      child: Center(
                        child: Text(
                          'Salut',
                          style: TextStyle(color: Colors.white),
                        ),
                      ),
                    ),
            ),
    );
  }
}```


I/ExoPlayerImpl(32436): Init eea22e1 [ExoPlayerLib/2.18.7] [beyond0, SM-G970F, samsung, 31] W/xample.driligh(32436): Accessing hidden method Landroid/media/AudioTrack;->getLatency()I (unsupported, reflection, allowed)
E/ExoPlayerImplInternal(32436): Playback error
E/ExoPlayerImplInternal(32436): com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal(32436): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:644)
E/ExoPlayerImplInternal(32436): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:614)
E/ExoPlayerImplInternal(32436): at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal(32436): at android.os.Looper.loopOnce(Looper.java:226)
E/ExoPlayerImplInternal(32436): at android.os.Looper.loop(Looper.java:313)
E/ExoPlayerImplInternal(32436): at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal(32436): Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, Mp3Extractor, AviExtractor, JpegExtractor) could read the stream.
E/ExoPlayerImplInternal(32436): at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92)
E/ExoPlayerImplInternal(32436): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1017)
E/ExoPlayerImplInternal(32436): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
E/ExoPlayerImplInternal(32436): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal(32436): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal(32436): at java.lang.Thread.run(Thread.java:920)




I added the necessary permission in the AndroidManifest file but I still get the same error.

2

Answers


  1. Chosen as BEST ANSWER

    Alright, for now I don't use to dipslay the video from a youtube link, I want to fix the error when picking a File from the local stroage using .file method.

    The video I wanna read is coming from a python backend server using websocket as Uint8List. So I have a function taht converts the Uint8List data into a video.mp4 file and then I try to read it. Here is the function that converts it:

    Future<void> convertListToVideoFile() async {
    final tempDir = await getTemporaryDirectory();
    final tempPath = tempDir.path;
    
    // Concatenate the Uint8List chunks into a single Uint8List
    final videoData = Uint8List.fromList(
      videoList.expand((list) => list).toList(),
    );
    
    // Create a new File in the temporary directory and write the video data
    final file = File('$tempPath/myVideo.mp4');
    await file.writeAsBytes(videoData);
    
    videoFile = file;
    notifyListeners();
    

    }


  2. Video Player Package supports only some valid formats of video, MP4 | HLS.

    The error message suggests that the video player is unable to recognize the format of the video stream.

    To solve the issue use another package, an example could be : youtube_player_flutter

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search