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

Stop the current video before starting a new one. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NextLight
Copy link
Contributor

This fixes the youtube app losing sync with the current playing video/position when starting a new video from the app while there was one already playing.

The reason why this happens is that for some reason xbmc.Player is reporting the old time and totalTime inside onPlayBackStarted, which causes report_now_playing to use the old values and YouTube gets confused by that.

There are other, more complicated ways to approach this issue.
The thing I don't like about this approach is that it has to wait for the player to close and than open again, but I feel like it's good enough since it doesn't take that long and it keeps things easy.

This fixes the youtube app losing sync with the current playing video/position
when starting a new video from the app while there was one already playing.
@enen92
Copy link
Owner

enen92 commented Apr 17, 2020

Maybe the addon should use onAVstarted event instead of onPlaybackStarted for all kodi versions since leia, this new event was not available by the time I build this plugin. By the time onPlaybackStarted is called, there's no guarantee a stream is already available in the player.

@NextLight
Copy link
Contributor Author

I did some testing and with onAVstarted it is reading the values correctly. (Thank you for that, I have never worked with kodi before)

There is another issues though: it seems like yt really wants to know from us that we stopped playing the video we were playing before before starting the new one. (which calling stop was doing for us)

We could call report_playback_stopped before play(url) but this way it triggers onPlayBackResumed (and sometimes __report_state_change inside the while loop) after the call to report_playback_stopped and it confuses youtube.

The working alternative is to call report_playback_stopped inside onAVstarted, just before report_now_playing. The downside to that is that we would sometimes set the status to stopped even though we weren't playing any video, but yt isn't complaining so it's fine I guess.

@enen92
Copy link
Owner

enen92 commented Apr 17, 2020

By the time onPlaybackStarted is triggered, the stream isn't yet available to Kodi's VideoPlayer. This means that our custom xbmc.Player implementation will hold the state of the last played item. So, on that event we could somehow report the stop event to youtube?

@enen92
Copy link
Owner

enen92 commented Apr 17, 2020

Can you explain a bit better how you're experiencing problems so I'm able to somehow reproduce the same behaviour?

@NextLight
Copy link
Contributor Author

Can you explain a bit better how you're experiencing problems so I'm able to somehow reproduce the same behaviour?

From the youtube app: start playing a video, wait a few seconds for kodi start playing it, then play another video without stopping the previous one (so that it enqueues it).
The yt app should become confused, disable the play/pause button and stop showing you the position.

@NextLight
Copy link
Contributor Author

By the time onPlaybackStarted is triggered, the stream isn't yet available to Kodi's VideoPlayer. This means that our custom xbmc.Player implementation will hold the state of the last played item. So, on that event we could somehow report the stop event to youtube?

I think that inside onPlayBackStarted it's in some hybrid state, for instance I believe that isPlaying is true even if it wasn't playing anything before.

I tested calling report_playback_stopped before report_now_playing some more and it's really working fine.
If we don't want to have it report that to yt even when it wasn't playing anything we could check whether it was playing something or not inside play_from_youtube and save it in a field so that we can check it later from within onAVStarted .

@prahal
Copy link

prahal commented Feb 1, 2024

@NextLight old code but could you check if the issue still exists with script.tubecast and youtube app clicking on play for two videos. I cannot reproduce with kodi 20.2 on Debian amd64 and latest script.tubecast 1.5.0+matrix.1, with youtube addon 7.0.2.2.
But I did not understand if in #44 (comment) you meant to enqueue a second video or play it directly so that it replaces the current one. So I tried both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants