Youtube_player_flutter: Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript ... )

Created on 15 Apr 2019  Â·  29Comments  Â·  Source: sarbagyastha/youtube_player_flutter

Hey there!

This package seemed to look pretty cool so I gave it a shot.
Unfortunately I get this error under iOS (haven't tested Android yet) when I hit the play button.

19:22:03.079 282 info flutter.tools [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'player.cueVideoById("secret-but-correct-video-id", 0)'

19:22:03.079 283 info flutter.tools Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type})

I did run pod install and also flutter clean. The video thumbnail is showing up in my view so I guess thats at least a partial success.

fixed

Most helpful comment

I just started using youtube_player_flutter and testing on an iPhone XR I still get the error.

On the Android emulator the video starts automatically and not on the iPhone.

When I click play on the video I get:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'play()'
Error Domain=WKErrorDomain Code=1 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred})

I am using

dependencies:
youtube_player_flutter: ^3.0.0+1

What can I do to fix the problem?

Thanks

All 29 comments

I am facing same error :

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'player.loadVideoById("iLnmTe5Q2Qw", 0)'
Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type})

0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)

1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)

2 WebViewController.evaluateJavascript (package:ytview/ytview.dart:590:22)

Thanks for reporting issue 😊 . The plugin is completely tested on Android only. Performing tests on iOS currently. Will push new version after tests complete, before this weekend.

Have the same issue, works great on android but on iOS I get the exception:

Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'player.playVideo()'
Error Domain=WKErrorDomain Code=2 "The Web Content process was terminated" UserInfo={NSLocalizedDescription=The Web Content process was terminated})

+1 and thanks for creating this plugin @sarbagyastha

Tested new Version 1.1.0 on iOS device and it works as intended, _but in simulator video starts playing only after 4-5 minutes (although the above mentioned error shows up) in my case._
Can you guys check whether or not it is working on real iOS device as well as simulator.

@sarbagyastha Still getting the same exception on iPhone 6s. Running 12.1.4

Hello,

@sarbagyastha Still getting the same exception too on iPhone 8. Running 12.1.2

Hi @sarbagyastha I've tested v1.1.0 on both a iOS 11 and 12 simulators (iPhone X, iPhone 8 etc) and a physical device (iPhone X) and it doesn't seem to be fixed.

I did manage to see a playing video on an iOS 11 simulator at one time, but only after 4-5 minutes like you described. When I restarted the simulator I got the error again:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'player.playVideo()'
Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type})

Done a little bit of debugging with Safari Web inspector, seems like the issue might be due to XHR ads related files. Will have to rewrite the iOS part i guess, so will take some time. If someone finds out workaround then a PR will be much appreciated. 😊

Compiler message:
file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/youtube_player_flutter-1.1.0/lib/src/youtube_player.dart:388:53: Error: The argument type 'Map' can't be assigned to the parameter type 'Set'.

  • 'Map' is from 'dart:core'.
  • 'Set' is from 'dart:core'.
  • 'AudiovisualMediaTypes' is from 'package:ytview/ytview.dart' ('file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/ytview-0.0.7+3/lib/ytview.dart').
    Try changing the type of the parameter, or casting the argument to 'Set'.
    mediaTypesRequiringUserActionForPlayback: {},
    ^
    Compiler failed on D:\AndroidStudioWorkspace\FlutterApps\my_smart_app\libmain.dart
    ******************
    WARNING: This version of image_picker will break your Android build if it or its dependencies aren't compatible with AndroidX.
    See https://goo.gl/CP92wY for more information on the problem and how to fix it.
    This warning prints for all Android build failures. The real root cause of the error may be unrelated.
    ******************
    Finished with error: Gradle task assembleDebug failed with exit code 1

Can you check what is issue, i can't run app
i am using youtube_player_flutter: ^1.1.0 plugins

@pmrajani , can you report with flutter doctor -v output.

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v1.1.8, on Microsoft Windows [Version 10.0.17134.1], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[!] Connected device
! No devices available

! Doctor found issues in 1 category.

@sarbagyastha Here it is

[√] Flutter (Channel beta, v1.1.8, on Microsoft Windows [Version 10.0.17134.1], locale en-US)
• Flutter version 1.1.8 at C:\src\flutter
• Framework revision 985ccb6d14 (4 months ago), 2019-01-08 13:45:55 -0800
• Engine revision 7112b72cc2
• Dart version 2.1.1 (build 2.1.1-dev.0.1 ec86471ccc)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\Admin\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jrebin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.

[√] Android Studio (version 3.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 33.4.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] Connected device
! No devices available

! Doctor found issues in 1 category.
@sarbagyastha

You're using older version of dart.. run flutter upgrade and the issue should be fixed.
Note: Set notation was only introduced in Dart 2.1.2 for Flutter.

@sarbagyastha it's works now thank you.

Done a little bit of debugging with Safari Web inspector, seems like the issue might be due to XHR ads related files. Will have to rewrite the iOS part i guess, so will take some time. If someone finds out workaround then a PR will be much appreciated.

@sarbagyastha Hello how about that problem? I am waiting your upgrade.

Please fix Failed evaluating JavaScript, JavaScript string was: 'player.playVideo()' issue ASAP.

@dmazlum @abeeriqbal , currently having a tight schedule so will work on it as soon I get adequate time for it.

@dmazlum @abeeriqbal , currently having a tight schedule so will work on it as soon I get adequate time for it.

Any update?

@abeeriqbal there is no update. I changed my player to webview. I embeded youtube code in webview. This is temporary solution. cheers

Any Update ?

This bug is affecting me also. Love the plugin though!

Sorry folks, due to lack of spare time I couldn't work on the issue. I will work on it from next weekend onwards.

The issue is finally fixed and will be updating the plugin tonight. It's working on iOS now.
https://imgur.com/L19WXgK

I just started using youtube_player_flutter and testing on an iPhone XR I still get the error.

On the Android emulator the video starts automatically and not on the iPhone.

When I click play on the video I get:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'play()'
Error Domain=WKErrorDomain Code=1 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred})

I am using

dependencies:
youtube_player_flutter: ^3.0.0+1

What can I do to fix the problem?

Thanks

I just started using youtube_player_flutter and testing on an iPhone XR I still get the error.

On the Android emulator the video starts automatically and not on the iPhone.

When I click play on the video I get:

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'play()'
Error Domain=WKErrorDomain Code=1 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred})

I am using

dependencies:
youtube_player_flutter: ^3.0.0+1

What can I do to fix the problem?

Thanks

Hello,

@sarbagyastha Still getting the same exception too on iPhone 8. Running 12.1.2

@sarbagyastha same error here.
Flutter version: 1.7.8+hotfix-3
youtube_player_flutter: ^3.0.0+1
device: iPhone 8 and iPhone X with iOS 12.3.1

@sarbagyastha I had the same issue. In my case, when value.isReady is still false, I got an error. So, I modified to display the indicator and wait until isReady changes.
It might be better to show progress indicator until isReady changes true.

@frgmt Done in Version 6.0.0

Was this page helpful?
0 / 5 - 0 ratings