Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Web: Video breaks when leaving fullscreen #311

Open
nstrelow opened this issue May 18, 2020 · 15 comments
Open

Web: Video breaks when leaving fullscreen #311

nstrelow opened this issue May 18, 2020 · 15 comments

Comments

@nstrelow
Copy link
Collaborator

nstrelow commented May 18, 2020

Chewie works nicely on web, which is awesome.

But if I go into fullscreen and leave again, it breaks the video and leaves it blank.

EDIT: Initially I though this was caused by the Wakelock.enable/disable function, which throw the error Error: MissingPluginException(No implementation found for method toggle on channel wakelock). But by removing Wakelock.enable/disable, the error log disappears but the video still breaks.

@nstrelow nstrelow changed the title Web: MissingPluginException when leaving FullScreen mode Web: MissingPluginException caused by Wakelock.enable/disable() May 18, 2020
@nstrelow nstrelow changed the title Web: MissingPluginException caused by Wakelock.enable/disable() Web: Video breaks when leaving fullscreen May 18, 2020
@tibe97
Copy link

tibe97 commented May 19, 2020

I'm having the same issue.

1 similar comment
@PreviousTlx
Copy link

I'm having the same issue.

@ErkinKurt
Copy link

Has anyone found a solution?

@nstrelow
Copy link
Collaborator Author

Is this fixed with the newest update?

@shatanikmahanty
Copy link

No

@shatanikmahanty
Copy link

I found a web only solution though

@nstrelow
Copy link
Collaborator Author

@shatanikmahanty Feel free to share ^^

@shatanikmahanty
Copy link

shatanikmahanty commented Nov 12, 2020

I am showing video in a popup you can do your own implementation

Make sure to import dart:js

void showVideoPopup(context, String link,) {

  final videoPlayerController = VideoPlayerController.network(link);

   bool isFullScreen = false;

final chewieController = ChewieController(
    videoPlayerController: videoPlayerController,
    aspectRatio: 3 / 2,
    autoPlay: false,
    looping: true,
    allowFullScreen: false,
    allowMuting: true,
    autoInitialize: true,
  );

showDialog(
    context: context,
    builder: (context) => AlertDialog(
      insetPadding: EdgeInsets.zero,
      content: Center(
        child: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: Stack(
            children: [
              Chewie(
                controller: chewieController,
              ),
              Positioned(
                top: 7,
                left: 10,
                child: CircleAvatar(
                  backgroundColor: Colors.grey[800],
                  child: IconButton(
                    icon: Icon(
                      Icons.fullscreen,
                      color: Colors.white,
                    ),
                    onPressed: () async {
                      if (!isFullScreen) {
                        document.documentElement.requestFullscreen();
                        await SystemChrome.setPreferredOrientations(
                            [DeviceOrientation.landscapeRight,DeviceOrientation.landscapeLeft]);
                      } else {
                        document.exitFullscreen();
                        await SystemChrome.setPreferredOrientations([
                          DeviceOrientation.portraitDown,
                          DeviceOrientation.portraitUp,
                        ]);
                      }

                      isFullScreen = !isFullScreen;
                    },
                  ),
                ),
              ),
            ],
          ),
        ),
      ),

      
      actions: [
        FlatButton(
          onPressed: () {
            // videoPlayerController.dispose();
            // chewieController.dispose();
            Navigator.of(context).pop();
          },
          child: Text(
            'Close',
            style: TextStyle(color: THEME_COLOR),
          ),
        )
      ],
    ),
  );

}

@shatanikmahanty
Copy link

shatanikmahanty commented Nov 12, 2020

Sorry I was bit late to comment but I implemented another web only solution using html and waited to complete both so that I can post together:

Note : Make sure you import -- >


import 'dart:html' as html;
import 'dart:ui' as ui;

Source :


String htmlContent(String link,double w, double h) {
  return """
<!DOCTYPE html> 
<html> 
<body> 

<center> <video width="$w" height="$h" controls>
  <source src="$link" type="video/mp4">
  <source src="$link" type="video/ogg">
  Your browser does not support HTML video.
</video> </center>

</body> 
</html>

""";
}

void showVideoPopup(context, String link) {

  String createdViewId = 'video_element$link';

  double w = MediaQuery.of(context).size.width/1.5,
      h = MediaQuery.of(context).size.height/1.5;

  String htmlVideo = Uri.dataFromString(htmlContent(link,w,h),
          mimeType: 'text/html', encoding: Encoding.getByName('utf-8'))
      .toString();


  // ignore: undefined_prefixed_name
  ui.platformViewRegistry.registerViewFactory(
      createdViewId,
      (int viewId) => html.IFrameElement()
        ..allowFullscreen = true
        ..src = "$htmlVideo"
        ..style.border = 'none');


  showDialog(
    context: context,
    builder: (context) => AlertDialog(
      insetPadding: EdgeInsets.zero,
      content: Center(
        child: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: HtmlElementView(
            viewType: createdViewId,
          ),
        ),
      ),
      actions: [
        FlatButton(
          onPressed: () {
            // videoPlayerController.dispose();
            // chewieController.dispose();
            Navigator.of(context).pop();
          },
          child: Text(
            'Close',
            style: TextStyle(color: THEME_COLOR),
          ),
        )
      ],
    ),
  );
}

@shatanikmahanty
Copy link

You will get this error "The name 'platformViewRegistry' is being referenced through the prefix 'ui', but it isn't defined in any of the libraries imported using that prefix". But this is an error in flutter web. If you search in Google you will find issue mentioned in Flutter framework github page.

Coming to the point, your code will run properly if you hit run on web.

Happy Coding ^^

@shatanikmahanty
Copy link

shatanikmahanty commented Nov 12, 2020

I found one useful discussion in stack overflow regarding conditional importing. You can use this to integrate a separate approach for web app without breaking the other platform builds. Link is below :

Platform specific imports discussion in Stack Overflow

@MichaelFerrier
Copy link

Is Chewie still being supported? This is a major bug that was opened 16 months ago and hasn't been addressed by devs in any way...

@ltOgt
Copy link

ltOgt commented Dec 7, 2022

Workaround: When closing, just reinitialise the controllers and pass through the position and isPlaying etc.

Not 100% smooth, but better than nothing

@nutfyb
Copy link

nutfyb commented Feb 22, 2023

Has anyone solved this problem now?

@ltOgt
Copy link

ltOgt commented Jan 16, 2025

I think this got fixed with #810

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants