honestbleeps / Reddit-Enhancement-Suite

Reddit Enhancement Suite
http://redditenhancementsuite.com
GNU General Public License v3.0
4.13k stars 881 forks source link

Closing expanded YouTube video doesn't correctly delete/stop the MPRIS connection #5364

Open zjeffer opened 2 years ago

zjeffer commented 2 years ago

What's the problem?

On Linux, I manage (play/pause) my media using the media keys on my keyboard. Say a video is playing in Firefox, I can play/pause even when the window is not in focus. Firefox added functionality a couple of months ago to use hardware media keys to control players like this.

When expanding a video, RES creates such a player that Firefox can control. Here's an example of such a connection seen in qdbusviewer:

image

As you can see in the image, I can control the video (play/pause/next/prev/...) and request information about it (PlyaBackStatus, Metadata, ...)

The problem is:

This means that when I open a YouTube video and then close it, media in that tab won't be controllable at all, because the tab thinks the first YouTube player is still playing. Only remedy is closing the tab and opening another one.

I use a script to always play the last paused mediaplayer (Spotify, Firefox, etc), and always pause the currently playing mediaplayer. When the player is "Playing" (first bulletpoint) or "Paused" (second bulletpoint), the script tries to play/pause the latest player it but nothing happens. This is kind of hard to explain so if I need to make a video showcasing how it works I can do that.

I believe the fix for this is to actually send the "Stop" signal to the MPRIS player when closing it (or completely delete the player?). That way, my script will just ignore it.

Are there any related posts in https://github.com/honestbleeps/Reddit-Enhancement-Suite/issues or /r/RESissues?

What other browser extensions are installed?

zjeffer commented 2 years ago

I believe the fix would be to change the pausecommand to a stopcommand here: https://github.com/honestbleeps/Reddit-Enhancement-Suite/blob/master/lib/modules/showImages.js#L1652

I've looked around in the code but I can't find what this command should be, and my knowledge of TypeScript is very limited. I hope someone else can fix this.

zjeffer commented 2 years ago

I just noticed the same behaviour in Windows. Very annoying.

indivisible commented 2 years ago

Seems to be a firefox bug

Extensions don't have dbus access (though native messaging helpers can cheat that), so it's not RES' fault. The player controls are even stuck between tab reloads!

zjeffer commented 2 years ago

@indivisible Thanks for creating a bug report! I never noticed it on another site, so naturally I thought it would be RES's fault.

However, I think stopping the player before removing the DOM would fix this as well. Knowing Firefox, fixing that bug will be pretty slow. Is this something RES devs could implement in the meantime, or should I close the issue?

indivisible commented 2 years ago

However, I think stopping the player before removing the DOM would fix this as well

Just tested this, and no, it does not work. I tried the YT api's stopVideo and destroy functions and neither help

zjeffer commented 2 years ago

Weird, when I press the stop button on my keyboard (which sends the MPRIS Stop method), the video stops and I can then close it fine without the bug happening.

indivisible commented 2 years ago

Weird, when I press the stop button on my keyboard (which sends the MPRIS Stop method), the video stops and I can then close it fine without the bug happening.

Yeah, it's a weird bug. I've not found anything that can be done to youtube embeds so far to fix this. I don't even know what's special about youtube's player that causes the bug: I've been unable to recreate the bug with simple video-tag-in-iframe so far

ElijahPepe commented 2 years ago

5397 should fix this.