jakky1 / video_player_win

Flutter video player for Windows, lightweight, using Windows built-in Media Foundation API. Windows implementation of the video_player plugin.
BSD 3-Clause "New" or "Revised" License
35 stars 11 forks source link

onErrorBuilder request #24

Closed explorer-source closed 11 months ago

explorer-source commented 11 months ago

While playing the network video, my app caches the video in temp dir so that the next time the user enters, it plays from the cache. When the user interrupts the download of the mp4 while it is not fully completed, it appears to crash without any error message. Is it possible to check for errors before playing so that I can play from the network instead or maybe just show error image?

jakky1 commented 11 months ago

As mentioned in README, you can detect is there something wrong when calling controller.initialize()

  controller.initialize().then((value) {
    if (controller.value.isInitialized) {
      controller.play();
      setState(() {});
    } else {
      log("video file load failed");
    }
  });

You can also detect error during playing by controller.value.errorDescription != null

explorer-source commented 11 months ago
if (fileExists) {
        videoController = WinVideoPlayerController.file(file);
      } else {
        videoController = WinVideoPlayerController.network(wholeUrl);
      }

      videoController.initialize().then((value) {
        if (videoController.value.isInitialized) {
          videoController.play();
          videoController.setLooping(true);
          videoLoaded = true;
          setState(() {});
        } else {
          print('video load failed');
        }
      });

isInitialized is not sufficient because I'm showing CircularProgressIndicator till videoLoaded becomes true yet it crashes

  return videoLoaded
          ? Center(
              child: Texture(
                textureId: videoController.textureId_,
                filterQuality: FilterQuality.medium,
              ),
            )
          : const Center(child: CircularProgressIndicator());
jakky1 commented 11 months ago

Could you upload the video file that can reproduce this issue ?

explorer-source commented 11 months ago

Ohh I found the problem, missing extension is the reason. I removed the extension from the file when saving to file so it doesn't show up as video in File explorer immediately for "security" reasons. You can change file from GxDhHlCNuO.mp4 to GxDhHlCNuO it crashes.