ja2375 / FluTube

A Flutter plugin to facilitate embedding Youtube videos inside mobile apps.
MIT License
34 stars 17 forks source link

How can I control the player and/or update videourl by button tap? #15

Closed emanuel-braz closed 2 years ago

emanuel-braz commented 4 years ago

Hi, I'm trying controlling the video player from my UI, but unfortunately, without success. Can you help me with that? I have tried GlobalKey, and it's not working too.

If there is no way to do that(change videourl), do you know how to completely rebuild the FluTube widget and load a new instance with new videourl?

GlobalKey<FluTubeState> myKey = new GlobalKey<FluTubeState>(); Got error: Multiple widgets used the same GlobalKey.

I also have tried with streams, but it only change the thumb.

class MyAppState extends State<MyApp> {

StreamController<String> streamController = new StreamController();

  String url1 = 'https://www.youtube.com/watch?v=hS9Zdt7L1LA';
  String url2 = 'https://www.youtube.com/watch?v=3LdnhBPL8Ds';

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[            
            StreamBuilder<String>(
              initialData: url1,
              stream: streamController.stream,
              builder: (context, snapshot) {                
                return FluTube(                                    
                  snapshot.data,
                  autoInitialize: true,
                  aspectRatio: 16 / 9,
                  allowMuting: false,
                  looping: true,
                  deviceOrientationAfterFullscreen: [
                    DeviceOrientation.portraitUp,
                    DeviceOrientation.landscapeLeft,
                    DeviceOrientation.landscapeRight,
                  ],
                  systemOverlaysAfterFullscreen: SystemUiOverlay.values,                  
                );
              }
            ),
            RaisedButton(
              child: Text('change videourl'),
              onPressed: (){
                streamController.add(url2);
              },
            )
          ],
        ),
      ),
    );
  }
}