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
709 stars 823 forks source link

Getting Cannot add new events after calling close error #782

Open chirag-chopra opened 1 year ago

chirag-chopra commented 1 year ago

Describe the bug Getting Cannot add new events after calling close after getting back from the screen which has youtube player

Expected behavior It should not give error. These error are getting recorded in firebase crashlytics too. There is not issue on screen but getting error in console

Screenshots If applicable, add screenshots to help explain your problem.

Technical Details:

Additional context Below are the console logs:

I/flutter ( 7921): ----------------FIREBASE CRASHLYTICS----------------
I/flutter ( 7921): Bad state: Cannot add new events after calling close
I/flutter ( 7921): #0      _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:243:24)
I/flutter ( 7921): #1      YoutubePlayerController.update
package:youtube_player_iframe/…/controller/youtube_player_controller.dart:348
I/flutter ( 7921): #2      YoutubePlayerEventHandler.onStateChange
package:youtube_player_iframe/…/controller/youtube_player_event_handler.dart:79
I/flutter ( 7921): #3      YoutubePlayerEventHandler.call
package:youtube_player_iframe/…/controller/youtube_player_event_handler.dart:41
I/flutter ( 7921): #4      new AndroidJavaScriptChannelParams.<anonymous closure>.<anonymous closure>
package:webview_flutter_android/src/android_webview_controller.dart:444
I/flutter ( 7921): #5      JavaScriptChannelFlutterApiImpl.postMessage
package:webview_flutter_android/src/android_webview_api_impls.dart:530
I/flutter ( 7921): #6      JavaScriptChannelFlutterApi.setup.<anonymous closure>
package:webview_flutter_android/src/android_webview.pigeon.dart:1312
I/flutter ( 7921): #7      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:214
package:flutter/…/services/platform_channel.dart:1
I/flutter ( 7921): ----------------------------------------------------

I also tried to handle error using dispose. Below is the code:

  late YoutubePlayerController? videoOne;
  late YoutubePlayerController? videoTwo;
  late YoutubePlayerController? videoThree;
  late YoutubePlayerController? videoFour;
  late YoutubePlayerController? videoFive;
  @override
  void dispose() {
    if (videoOne != null) videoOne!.close();
    if (videoTwo != null) videoTwo!.close();
    if (videoThree != null) videoThree!.close();
    if (videoFour != null) videoFour!.close();
    if (videoFive != null) videoFive!.close();
    super.dispose();
  }
sarbagyastha commented 1 year ago

Which version are you using ?

chirag-chopra commented 1 year ago

youtube_player_iframe: ^4.0.4

mojago commented 1 year ago

I also experience this bug with ^4.04, it wasn't an issue with ^4.01.

chirag-chopra commented 1 year ago

Still getting same error... 👎

davidgalarza commented 1 year ago

Any update?? I'm facing the same issue

yokawaiik commented 1 year ago

Faced the same error when closing the page. Dispose does not solve the problem. Needs to be fixed as soon as possible.

Version: 4.0.4

hagen00 commented 1 year ago

I would love a fix here as well! Looks like the PR just needs merging? https://github.com/sarbagyastha/youtube_player_flutter/pull/730