Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Next Video Playing, State change #108

Closed
SayaGames opened this issue Oct 31, 2019 · 15 comments
Closed

Next Video Playing, State change #108

SayaGames opened this issue Oct 31, 2019 · 15 comments
Assignees
Labels
enhancement New feature or request fixed

Comments

@SayaGames
Copy link

SayaGames commented Oct 31, 2019

Hi,
I need to play random video from a playlist. In the listener method, I can catch endstate and generate random video from a playlist. But PlayerState doesn't pass to playing state.

MY CODE SNIPPET:
void listener() {
if (_controller.value.playerState == PlayerState.ended ) {
....

    _controller.load( YoutubePlayer.convertUrlToId(<MY VIDEO URL),startAt:0);
    _controller.play();
  setState(() {});

(After trying dozens of times, automatically, gives this error:)
ERROR:
════════ Exception caught by foundation library ════════════════════════════════════════════════════
The following StackOverflowError was thrown while dispatching notifications for YoutubePlayerController:
Stack Overflow

@SayaGames SayaGames added the bug Something isn't working label Oct 31, 2019
@sarbagyastha
Copy link
Owner

I'll look into it.

@sarbagyastha
Copy link
Owner

Fixed in Version 6.0.0.

@sarbagyastha sarbagyastha added fixed and removed bug Something isn't working labels Nov 2, 2019
@up2code
Copy link

up2code commented Nov 5, 2019

I had tested on 6.0.0 and player state stoped is called instead of ended when player reach end. Should I change to check stoped state instead of ended state?

@sarbagyastha
Copy link
Owner

sarbagyastha commented Nov 5, 2019

Once video ends, ended is fired once, then it switches to stopped. So, you might want to listen for ended, because stopped could be fired multiple times if parent state changes.

See the implementation here.

@up2code
Copy link

up2code commented Nov 5, 2019

I tried to print playerState to see if ended will be fired.

YoutubePlayer(
   showVideoProgressIndicator: true,
    controller: _controller,
    onReady: () {
       _controller.addListener(() {
             print(_controller.value.playerState);
      });
    },
)

but no ended is called or updated in listener. Below is list of state that updated.

I/flutter (  469): PlayerState.playing
I/flutter (  469): PlayerState.playing
I/flutter (  469): PlayerState.playing
V/AudioManager(  469): unregisterAudioFocusListener...
I/AudioManager(  469): abandonAudioFocus
I/chromium(  469): [INFO:CONSOLE(1179)] "'HTMLVideoElement.webkitExitFullscreen()' is deprecated. Please use 'Document.exitFullscreen()' instead.", source: https://www.youtube.com/yts/jsbin/player_ias-vflpFCqgL/en_US/base.js (1179)
I/flutter (  469): PlayerState.playing
I/flutter (  469): PlayerState.playing
I/flutter (  469): PlayerState.stopped
I/flutter (  469): PlayerState.stopped
D/        (  469): PlayerBase::stop() from IPlayer

@sarbagyastha
Copy link
Owner

sarbagyastha commented Nov 5, 2019

It's weird, the state shouldn't switch to stopped unless ended is triggered.

@amangautam1
Copy link

ended is being called once, but when placing
_controller.load( videoId);
inside listener is crashing UI. When doing same thing in shackbar click action everything works fine.
I think, the player state doesn't change when loading video inside listener.

@sarbagyastha
Copy link
Owner

@amangautam1 Please attach logs for the UI crash.

@amangautam1
Copy link

this is my listener.
void listener() { if (_isPlayerReady) { if (_controller.value.playerState == PlayerState.ended) { print("video ended"); _controller.load(list[index+1].videoId); } } }

and these are logs.

I/chromium(27484): [INFO:CONSOLE(1182)] "'HTMLVideoElement.webkitExitFullscreen()' is deprecated. Please use 'Document.exitFullscreen()' instead.", source: https://www.youtube.com/yts/jsbin/player_ias-vflaGJCFN/en_US/base.js (1182)
I/flutter (27484): video ended
I/chatty (27484): uid=10184(com.example.flutter_iigs) 1.ui identical 1481 lines
I/flutter (27484): video ended

�[38;5;248m════════ Exception caught by foundation library ════════════════════════════════�[39;49m
Stack Overflow
�[38;5;248m════════════════════════════════════════════════════════════════════════════════�[39;49m
W/cr_MediaCodecBridge(27484): Releasing: OMX.qcom.video.decoder.avc
W/chromium(27484): [WARNING:audio_sync_reader.cc(187)] ASR: No room in socket buffer.: Broken pipe (32)
D/ (27484): PlayerBase::stop() from IPlayer
D/AudioTrack(27484): stop() called with 1404152 frames delivered
D/SurfaceUtils(27484): disconnecting from surface 0x6fc890d010, reason disconnectFromSurface
W/MediaAnalyticsItem(27484): Unable to record: (codec:0:-1:-11:0:11:android.media.mediacodec.mime=video/avc:android.media.mediacodec.mode=video:android.media.mediacodec.encoder=0:android.media.mediacodec.codec=OMX.qcom.video.decoder.avc:android.media.mediacodec.secure=0:android.media.mediacodec.width=1280:android.media.mediacodec.height=720:android.media.mediacodec.rotation-degrees=0:android.media.mediacodec.maxwidth=1280:android.media.mediacodec.maxheight=720:android.media.mediacodec.bytesin=1134300:) [forcenew=0]
W/cr_MediaCodecBridge(27484): Codec released
I/zygote64(27484): Background concurrent copying GC freed 89872(11MB) AllocSpace objects, 0(0B) LOS objects, 77% free, 3MB/15MB, paused 142us total 463.304ms

�[38;5;248m════════ Exception caught by image resource service ════════════════════════════�[39;49m
HTTP request failed, statusCode: 404, https://i3.ytimg.com/vi/IW1LyIgmbDk/sddefault.jpg
�[38;5;248m════════════════════════════════════════════════════════════════════════════════�[39;49m
W/InputEventReceiver(27484): Slow Input: 329ms so far, now at dispatchInputEvent (KeyEvent: event_seq=214, seq=1688998, code=KEYCODE_BACK, action=ACTION_DOWN)
W/InputTransport(27484): Slow Input: 344ms so far, channel 'ClientState{5b6bf31 uid 10184 pid 27484} (server)' publisher ~ publishKeyEvent: seq=1, deviceId=4, source=0x101, action=0x0, flags=0x48, keyCode=4, scanCode=158, metaState=0x0, repeatCount=0,downTime=191554815000000, eventTime=191554815000000
W/InputEventReceiver(27484): Slow Input: took 145ms in dispatching, now at finishInputEvent (KeyEvent: event_seq=214, seq=1688998, code=KEYCODE_BACK, action=ACTION_DOWN)
W/InputEventReceiver(27484): Slow Input: 367ms so far, now at dispatchInputEvent (KeyEvent: event_seq=215, seq=1689000, code=KEYCODE_BACK, action=ACTION_UP)
W/InputTransport(27484): Slow Input: 367ms so far, channel 'ClientState{5b6bf31 uid 10184 pid 27484} (server)' publisher ~ publishKeyEvent: seq=2, deviceId=4, source=0x101, action=0x1, flags=0x48, keyCode=4, scanCode=158, metaState=0x0, repeatCount=0,downTime=191554815000000, eventTime=191554923000000
I/flutter (27484): completed
I/flutter (27484): completed
W/ContentCatcher(27484): Failed to notify a WebView
W/Adreno-ES20(27484): <core_glFinish:34>: glFinish skipped: 0
W/Adreno-ES20(27484): <core_glFinish:34>: glFinish skipped: 0
W/Looper (27484): Slow Frame: doFrame is 364ms late
W/Adreno-ES20(27484): <core_glFinish:34>: glFinish skipped: 0
E/flutter (27484): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method evaluateJavascript on channel plugins.flutter.io/webview_0)
�[38;5;244mE/flutter (27484): #0 MethodChannel.invokeMethod�[39;49m
E/flutter (27484):
�[38;5;248mE/flutter (27484): #1 MethodChannelWebViewPlatform.evaluateJavascript�[39;49m
�[38;5;248mE/flutter (27484): #2 WebViewController.evaluateJavascript�[39;49m
�[38;5;248mE/flutter (27484): #3 YoutubePlayerController._evaluateJS�[39;49m
�[38;5;248mE/flutter (27484): #4 YoutubePlayerController.pause�[39;49m
�[38;5;248mE/flutter (27484): #5 YPlayerState.dispose�[39;49m
�[38;5;244mE/flutter (27484): #6 StatefulElement.unmount�[39;49m
�[38;5;244mE/flutter (27484): #7 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #8 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #9 SingleChildRenderObjectElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #10 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #11 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #12 ComponentElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #13 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #14 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #15 SingleChildRenderObjectElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #16 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #17 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #18 SingleChildRenderObjectElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #19 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #20 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #21 ComponentElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #22 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #23 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #24 SingleChildRenderObjectElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #25 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #26 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #27 SingleChildRenderObjectElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #28 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #29 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #30 ComponentElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #31 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #32 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #33 ComponentElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #34 _InactiveElements._unmount�[39;49m
�[38;5;244mE/flutter (27484): #35 _InactiveElements._unmount.�[39;49m
�[38;5;244mE/flutter (27484): #36 ComponentElement.visitChildren�[39;49m
�[38;5;244mE/flutter (27484): #37 _InactiveElements._unmount�[39;49m
E/flutter (27484): #38 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1

@sarbagyastha
Copy link
Owner

@amangautam1 Which version of the package are you using ?

@amangautam1
Copy link

@sarbagyastha I am using version ^6.0.0

@sarbagyastha
Copy link
Owner

@amangautam1 can you provide me with sample app so that i can reproduce and test the issue ?

@amangautam1
Copy link

@sarbagyastha I have sent you the sample app on gmail. Please check it.

@sarbagyastha
Copy link
Owner

@amangautam1 Thank you! There seems to be weird behaviour while listening to ended state. It's being called multiple times though console outputs only once. I'll be pubslishing fix for it tomorrow.

@sarbagyastha sarbagyastha added bug Something isn't working WIP Work In Progress and removed fixed labels Nov 14, 2019
sarbagyastha pushed a commit that referenced this issue Nov 15, 2019
@sarbagyastha
Copy link
Owner

@amangautam1 Added onEnded callbackProperty to YoutubePlayer in Version 6.0.2.

YoutubePlayer(
    ... ,
    onEnded: (_){
          controller.load(NEXT_VIDEO);
    }
),

Also, the example app is updated with list of videos being played after video end events.

@sarbagyastha sarbagyastha added enhancement New feature or request fixed and removed WIP Work In Progress bug Something isn't working labels Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed
Projects
None yet
Development

No branches or pull requests

4 participants