sarbagyastha / youtube_player_flutter

A Flutter plugin for inline playback or streaming of YouTube videos using the official iFrame Player API.
https://youtube.sarbagyastha.com.np
BSD 3-Clause "New" or "Revised" License
708 stars 820 forks source link

iOS causes Progress to display and video doesnt load[BUG] #274

Open bpaul7101 opened 4 years ago

bpaul7101 commented 4 years ago

I am using Flutter 1.17.x and have a few issues with the plugin with respect to iOS :-

1) I get

flutter: type 'int' is not a subtype of type 'double' in type cast

being displayed constantly

2) The plugin works the first 2 times but when I navigate to a page the 3rd,4th, 5th etc time - I just get a spinning progress bar.

Is this a KNOWN issue in iOS or do you need any other config in info.plist, ?

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Simple code for the player is :


class YouTubePlayer extends StatefulWidget {
  @override
  _YouTubePlayerState createState() => _YouTubePlayerState();
}

class _YouTubePlayerState extends State<YouTubePlayer> {
  YoutubePlayerController _controller;
  @override
  void initState() {
    _controller = YoutubePlayerController(
      initialVideoId: 'YOUR VIDEO',
      flags: YoutubePlayerFlags(
        autoPlay: true,
        mute: false,
      ),
    );

    super.initState();
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () {
        if (DeviceHelper.isPhone(context)) {
          SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
        } else {
          // Tablet - allow
        }
        return Future.value(true);
      },
      child: Scaffold(
        appBar: AppBar(title: Text('App Video')),
        body: YoutubePlayerBuilder(
            player: YoutubePlayer(
              controller: _controller,
              showVideoProgressIndicator: true,
            ),
            builder: (context, player) {
              return Column(
                children: [
                  player,
                 ],
              );
            }),
      ),
    );
  }
}
abineshamatya commented 4 years ago

Same issue with the Android after the flutter upgrade. It just shows the progress loader and the video doesn't get loaded at all.

ricardocaste commented 4 years ago

Same issue in iOS

alexda12 commented 4 years ago

I have same issue ... in the end I ended up just using the flutter webview plugin , works perfectly to show a youtube video without any spinning progress bar etc ...

Strat68 commented 4 years ago

Hey all, I am having the exact same problem. My app simply grabs youtube videos organized by playlist. Sometimes they load, sometimes not...all the time it takes too much time (spinning circle) even more when not connected to wifi.

does the webview plugin solve all of this? what about when you turn the screen sideways? no problems at all?

thanks!

Strat68 commented 4 years ago

@alexda12 any update on how your solution is performing?

MsXam commented 4 years ago

@Strat68. Unfortunately - this plugin has some issues with regards to the video stopping 1/2 way, spinning progress showing intermittently, caching issues plus rotation problems (Android).

I have had 100% success adapting the webview plugin.

Rotation is easy to accomplish with the plugin, it has support for offline caching and a builder for an initial widget to show whilst it streams your video ...

I would recommend adopting this component if you need to stream YT videos ... should take no more than 10-15 mins to implement.,

Strat68 commented 4 years ago

Thank you, ill give it a try

davlinski commented 4 years ago

@MsXam Can you please clarify which "webview" plugin you used? The plugin in question (youtube_player_flutter) relies on "flutter_inappwebview" (written by pichillilorenzo@gmail.com), but there is also the official "webview_flutter" (written by flutter.dev) as well as "flutter_webview_plugin" (written by fluttercommunity.dev). My head is spinning trying to determine which plugin will actually work AND not violate YouTube's terms of service! I just posted on a thread that is several years old asking for some sort of "official" plugin, where all of the Flutter devs seem to dismiss such a notion as a waste of time (for them anyway). This can't just be some ancillary, unimportant issue for them. YouTube is a revenue machine! I would think they would want to drive as many viewers as possible to their platform! I'm perplexed. Your help is greatly appreciated!!

MsXam commented 4 years ago

@davlinski The plugin you require is the flutter_webview_plugin: 0.3.11, i.e here :

https://pub.dev/packages/flutter_webview_plugin

Since my projects have been created pre 1.12 and are Obj-c based, other similar plugins were incompatible because of new Android changes relating to new Java Embedding format , hence it was too much trouble moving my entire app over to support this.

If you do go for this plugin that I have mentioned here, remember that the webview is not integrated into the widget tree - this may not be an issue to you if you just intend to nest Youtube videos and nothing else ...

Additionally you will need to add some simple code to handle rotation in Android and remove the AppBar in Landscape mode - iOS this is handle automatically for you...

Lastly, i'm unsure of your comment here :

which plugin will actually work AND not violate YouTube's terms of service!

In effect all you are doing by using this plugin is having an embedded browser that just services your URL ...

Strat68 commented 4 years ago

@davlinski The plugin you require is the flutter_webview_plugin: 0.3.11, i.e here :

https://pub.dev/packages/flutter_webview_plugin

Since my projects have been created pre 1.12 and are Obj-c based, other similar plugins were incompatible because of new Android changes relating to new Java Embedding format , hence it was too much trouble moving my entire app over to support this.

If you do go for this plugin that I have mentioned here, remember that the webview is not integrated into the widget tree - this may not be an issue to you if you just intend to nest Youtube videos and nothing else ...

Additionally you will need to add some simple code to handle rotation in Android and remove the AppBar in Landscape mode - iOS this is handle automatically for you...

Lastly, i'm unsure of your comment here :

which plugin will actually work AND not violate YouTube's terms of service!

In effect all you are doing by using this plugin is having an embedded browser that just services your URL ...

Thanks for helping Davlinski! He needs all the help he can get LOL!

davlinski commented 4 years ago

Lastly, i'm unsure of your comment here :

which plugin will actually work AND not violate YouTube's terms of service!

In effect all you are doing by using this plugin is having an embedded browser that just services your URL ...

@MsXam I'm just referring to a comment on the thread asking for an official YouTube plugin: https://github.com/flutter/flutter/issues/13756#issuecomment-490497865

The commenter lists several YouTube plugins and mentions that they all violate YouTube terms of service. Thankfully, none of the webview plugins are listed.

Thanks for your help!

Strat68 commented 4 years ago

@MsXam we attempted to use the plugin you recommended but videos are slow to start playing especially over wifi. Is there any way to fix this and make it faster?

When a video is initiated, i watch the "loading spinner" run for 20 seconds before it starts. as a comparison...the youtube app plays videos almost instantly even over wifi.

sarbagyastha commented 4 years ago

@MsXam The reason why this package exists is to support inline playback and custom controls. And as per your comment, seems like you donot want an inline player, for that purpose, you can try using flutter_youtube. It's based off native plugins.

sarbagyastha commented 4 years ago

Sorry for the delay, was not being able to address all the issues with the plugin. I am currently refactoring the plugin and that should address the issues. But due busy schedules these days, the refactoring is being slow. 😣

Strat68 commented 4 years ago

@sarbagyastha You are correct...i was originally using the flutter_youtube player but it was extremely slow with video initiation.

I hope your updates work, thanks!

sarbagyastha commented 4 years ago

Please try with youtube_player_iframe.