betterplayer icon indicating copy to clipboard operation
betterplayer copied to clipboard

Can BetterPlayer automatically detect aspect ratio?

Open magnuswikhog opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. I'm loading videos from online (Firebase Storage), the aspect ratio could be different for each video, so I can't set it manually. I was expecting BetterPlayer to automatically detect the aspect ratio and resize the widget accordingly, but I can't find any info on how to do it. Everything related to aspect ratios that I find is either just related to fullscreen, or examples where the aspect ratio is hard coded.

Describe the solution you'd like I'm 99% sure that info about aspect ratio is in the video files, so the expected default behaviour would be that the widget sizes itself accordingly (after loading/buffering the video of course).

Describe alternatives you've considered Not sure what my alternatives would be. I can't hard code aspect ratios since they could be different from one video to another. Maybe I could store the information somewhere (in the filename, in Firebase, etc), but that seems like a super hacky way of accomplishing something that should be a no-brainer in 2022...

Additional context

magnuswikhog avatar Jul 05 '22 09:07 magnuswikhog

Hi Magnus!

I faced the same problem, could extract the aspect ratio from the videoPlayerController.

Example:

  void initState() {
    final betterPlayerDataSource =
        BetterPlayerDataSource(BetterPlayerDataSourceType.network, widget.videoUrl);
    betterPlayerController = BetterPlayerController(
      betterPlayerDataSource: betterPlayerDataSource,
    );

    betterPlayerController?.addEventsListener((BetterPlayerEvent event) {
      if (event.betterPlayerEventType == BetterPlayerEventType.initialized) {
        betterPlayerController
            ?.setOverriddenAspectRatio(betterPlayerController!.videoPlayerController!.value.aspectRatio);
        setState(() {});
      }
    });

Phil9l avatar Sep 19 '22 10:09 Phil9l

Hi Magnus!

I faced the same problem, could extract the aspect ratio from the videoPlayerController.

Example:

  void initState() {
    final betterPlayerDataSource =
        BetterPlayerDataSource(BetterPlayerDataSourceType.network, widget.videoUrl);
    betterPlayerController = BetterPlayerController(
      betterPlayerDataSource: betterPlayerDataSource,
    );

    betterPlayerController?.addEventsListener((BetterPlayerEvent event) {
      if (event.betterPlayerEventType == BetterPlayerEventType.initialized) {
        betterPlayerController
            ?.setOverriddenAspectRatio(betterPlayerController!.videoPlayerController!.value.aspectRatio);
        setState(() {});
      }
    });

Thanks for the solution, it works! It is really unexpected that the aspect ratio is not calculated by BetterPlayer, since this functionality is present in the video_player and chewie projects.

brunogc avatar Sep 22 '23 17:09 brunogc