NDevTK / AutoPause

Browser extension to pause other audio and video sources if audio is playing on the active tab with automatic resume, fast forward and media controls.
https://addons.mozilla.org/firefox/addon/autopause/
MIT License
31 stars 6 forks source link

Potentially not wanted third tab behavior #7

Closed NDevTK closed 3 years ago

TheBlackRoom commented 3 years ago

Unwanted behaviour: Three tabs open, two of which are YouTube, the other is a non Audio-visual (AV) tab. AutoPause seems to work fine switching between the two AV tabs, but when I switch to the non-AV tab, both AV tabs start to play their audio and video.

Desired behaviour: Both AV tabs should completely pause/stop until I return to either one of them, upon which that AV tab should carry on playing where it left off just as it does when only switching between the two AV tabs.

The Alt+r toggle doesn't seem to help in this respect and is quite confusing in how it operates - it doesn't have any immediate affect if I'm currently on the third non-AV tab until returning to one of the AV tabs but then only after switching to the other AV tab.

There also seems to be no visual clue as to which state the Alt+r toggle is in and it's easy to get in a mess of clicking play-buttons to work out what toggled state everything is currently in.

To be honest, I don't see the need for the Alt+r toggle, just make AutoPause stop playing anything when no AV tabs are selected and resume an AV tab when it is. Having to use a two-key toggle to try and stop things is much more mental and physical work than simply remembering to press the pause button on the current tab before switching away.

However, I can see a need for a tab to sometimes carry on playing such as when listening to radio/audio or when wanting to hear a live video stream without necessarily watching, so perhaps that would make a useful toggle.

Hope that helps, otherwise for just AV tabs alone, AutoPause works very well.

TheBlackRoom commented 3 years ago

In case it's relevant, I'm running Firefox on Windows 10 and using the Tree Style Tab extension (for vertical tabs).

NDevTK commented 3 years ago

"make AutoPause stop playing anything when no AV tabs are selected and resume an AV tab when it is" this would stop any background audio.

TheBlackRoom commented 3 years ago

Maybe I'm missing something about what your extension is supposed to be, but I don't want any background audio to carry on playing or anything else carrying on when I switch away from say a YouTube video, BBC News, or whatever - The page I move to might have it's own things I want to watch or listen to at some point or I may just need things to pause while I reference something else or do another task and I often have several tabs of audio/video paused waiting for me to continue them later, especially tutorials.

TheBlackRoom commented 3 years ago

Even if I did want audio to carry on, I would want all streams in various tabs to play at once!

(EDIT) Woops, wouldn't not would want all streams...

NDevTK commented 3 years ago

Maybe:

TheBlackRoom commented 3 years ago

I guess your ideas would do what I was thinking.

I just want any currently playing active AV tab to pause when I click away. If that's to a non-AV tab then do nothing else, if it's to another previously paused tab, for it to then carry on where it left off.

If you can do that then AutoPause would be perfect.

NDevTK commented 3 years ago

It has now been added with alt+i using this build https://github.com/NDevTK/AutoPause/actions/runs/474063141 this will pause on tab change.

For multiple tab resume system fix I think it might be better to allow the user to mark the tab that gets auto resumed.

TheBlackRoom commented 3 years ago

Thanks for coming up with this and I'd love to try it but I can't manage to install it. I have tried a few times and set the about:config setting xpinstall.signatures.required to false but when dragging the download I found at the link called "firefox.zip" to the Add-ons manager Firefox says it "has prevented this site from installing unverified add-ons".

Am I doing something wrong or is there a problem with the file?

Firefox build 84.0.2 (64-bit)

NDevTK commented 3 years ago

Go to about:debugging#/runtime/this-firefox and click Load temporary addon.

TheBlackRoom commented 3 years ago

Okay, I got it installed and on initial testing of three playing YouTube videos and then hitting Alt+i it seemed to be working well. Well done, each video pausing when making the one of the others active.

However, on further testing the are still some bugs. I will try and list the oddities here.

1) With only one tab playing (the others not started yet or AutoPause paused), switching to another tab does not pause the current singular event of something playing. Only when pressing play on that second tab does AutoPause start to do its stuff - it needs to do it the moment the first tab becomes not the active tab.

2) There are some similar oddities when two or more tabs are set to be playing (and all but the current playing one paused by AutoPause), and then switching to another tab that has a video lined up to play (or is paused by the YouTube control). When this happens, all of the other non-active tabs start playing.

3) After using the Alt+i toggle once I now don't seem to be able to revert it's toggle action.

4) I may be missing something but as far as I can tell, so far with AutoPause it is not possible to easily determine the current state of the toggles. Is it possible to somehow include an easy visual method for us to be able to see which way things are currently toggled or at least maybe have it viewable/switchable/checkable in Options or give it icon in the menu bar (or perhaps a context menu)?

Thanks for your keen and great work, I have just edited my review on Mozilla and changed the rating to 5 for your work so far. Thanks again.

NDevTK commented 3 years ago

does this work for you? https://github.com/NDevTK/AutoPause/actions/runs/474539671

NDevTK commented 3 years ago

The state of the toggles are now in the options page. In the updates theirs also alt+o to mark a background tab so only one gets resumed.

TheBlackRoom commented 3 years ago

I've tested that new version - you say the state of the toggles are now in the options page and I've just worked out the first one (disable automatic resume) is Alt-r, and the other (pause on tab change instead of waiting for new media) is Alt-i.

By having just the second option selected (Alt-i) AutoPause is now doing everything I was wanting - brilliant!

When selecting both options I noticed some oddities: I play one tab's video and then move to another (not playing) tab and the first tab keeps playing (it fails to pause), then select another tab (or yet another) and then sometimes the first tab's video did pause (but most times not). If on selecting the second video tab after the first is playing, and pressing play for that second tab, then the videos WILL pause for further tabs selected after that. I'm not sure if this behaviour is consistent or affected by Alt-o (tab continue or resume, I'm not sure!?). It seems to keep a tab playing when moving away to another but that might be the above bug. It only works when the first option (disable automatic resume) is selected. It has to be used when the media is playing on the active tab. If then going to another media tab and playing that it then deactivates the first tab's playing where using Alt-o again will do the action to the second tab. That said, on trying it again while testing it's becoming less clear what it really does and I'm finding that I am losing track of what state the toggle is actually in. We really need some visual clues.

With Alt-i active and nicely pausing several playing media tabs, when moving to any other preloaded tab, Alt-k still manages to jump back to the last active media tab (and un-pause it) but only if it was within the preceding four preloaded tabs selected. Switching to a fifth preloaded or a first non-preloaded tab makes Alt-k do nothing.

That's all the testing I've been able to do and confirm, hope that helps.

NDevTK commented 3 years ago
TheBlackRoom commented 3 years ago

That's what I was trying to explain - Alt+k will return properly to the last active audible tab so long as the tab that I'm currently on was already a fully loaded tab, i.e. not from what was an unloaded (like after a restart) before clicking on it. I then found there was a maximum of four preloaded tabs it would work for, after the fifth AP would fail to return to the last active audible tab.

I'd swear I did get Alt+o working as you described for a while but then I got in a muddle after lots of testing (and it only worked while Alt-r was active.

TheBlackRoom commented 3 years ago

For Alt-k, if the (secondary) tab had not been pre-loaded, the jump back to an audible tab would fail - something to do with the reload resetting things.

NDevTK commented 3 years ago

Strange :/ Have you read the code? Im trying get the resume feature to work better for multiple tabs.

TheBlackRoom commented 3 years ago

I'm not an expert on code or GitHub, though I do understand the principles. I'm better with HTML/CSS and I can get the gist of what is happening with code/js/php, etc. I have now glanced through the files and I'm taking an educated guess that the two main files are background.js and ContentScript.js. I see there's "resume" stuff going on in background.js around lines 47, 48, 56 75, 79 and 104 but I'm powerless to fully grasp the issues.

Can I just ask, what happens if there is no audible stream to the tab (e.g. if audio is absent from a video), like in a silent animation)?

I have tried to understand GitHub over the years and it still freaks me out. It's not for end-users and it seems to make no attempt at becoming so or making things seem as though they can be presented in a way that makes people like me (a semi-interested coder/designer) become more informed. I'd love to help but unless you can pinpoint the areas you're looking at, and what I might do with them, I'm at a bit of a loss.

NDevTK commented 3 years ago

if audio is absent from a media element it would currently not detect it. It would have to send a message from contentscript.js (code per tab) to the background.js file like https://developer.chrome.com/docs/extensions/mv2/messaging/#simple because the content script can listen to page events like https://github.com/NDevTK/AutoPause/blob/master/ContentScript.js#L44 this would need to have a permission for the website however the audible value does not from the tabs api https://developer.chrome.com/docs/extensions/reference/tabs/

Issue: https://github.com/NDevTK/AutoPause/issues/8

current css is bad: https://github.com/NDevTK/AutoPause/blob/master/options.css

TheBlackRoom commented 3 years ago

I apprecaite your suggestions and nudges - I'll try and look at it tomorrow with a fresher mind but I can't say I'll be able to do much! I had noticed your options layout was lacking at the moment. I've glanced at your CSS and it is rather a small set of styling features so far!. Is doing CSS for Add-ons the same as ordinary web pages or is there something like a predefined framework of tags and settings to use for general consistency? I suppose not, as these are add-ons/extensions are for any browser so I guess layout and style is down to the author(s).

NDevTK commented 3 years ago

Okay

NDevTK commented 3 years ago

There is css at chrome://browser/content/extension.css (even for firefox) https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/options_ui

TheBlackRoom commented 3 years ago

I can see you've been working hard and all hours on this. I've been there in the past staying up all hours reading forums and figuring things out the hard way. I've kind of had to give that up these days as I couldn't take the strain and I'm not young any more.

Thanks for your hard work and I admire the way you have jumped to the challenge of my suggestions and taken them onboard. I'm in the UK and it's now very late. Time for bed!

TheBlackRoom commented 3 years ago

Thanks for the css links - I was wondering how it works that you can develop for Chrome & Firefox at the same time - I shall have to explore.

NDevTK commented 3 years ago

They added the chrome namespace https://extensionworkshop.com/documentation/develop/porting-a-google-chrome-extension/

NDevTK commented 3 years ago

https://github.com/NDevTK/AutoPause/actions/runs/476567033

TheBlackRoom commented 3 years ago

Seems to be working in my testing:

Alt-o only works if At-i is off and Alt-r is on (this seems an okay concept given what those options do).

For silent media test I used a YouTube video of black nothing at: https://www.youtube.com/watch?v=I_6ZcOo6pnk - I assume it has no audio track?

For Alt-k I found only works when the tab I'd switched to was a preloaded one (not an unloaded one say after a browser restart of unloaded tabs from a previous session). Alt-k would also function well to switch between two tabs set to playing media (pausing each on switching away).

For me, just having Alt-i on is perfect for my general use of pausing videos/audio instantly when I switch away to another tab. knowing about the Alt-o is useful to know if I want to keep something playing when I switch away but to enable that I have to turn off Alt-i, enable Alt-r, then hit Alt-o (on a playing media tab). I assume switching back is a rough reversal of that, so I'm wondering if you can think of a better way to switch between modes of operation while at the same time having it possible to easily determine the current state of everything, e.g, visual icon overlays, a context menu or some other subtle visual point and click control system?

Other than those notes, brilliant work! Thanks.

NDevTK commented 3 years ago

Alt-k will only work if the browser is playing the media this might be changed.

NDevTK commented 3 years ago

Silent video now seems to work correctly. I have made some changes to tab resume do you think it works better now? Alt-k will now fallback to the last played media https://github.com/NDevTK/AutoPause/blob/master/background.js#L64 does this fix the problem as I dont know how to test it.

NDevTK commented 3 years ago

@TheBlackRoom this issue seems to be fixed in version 2.3 🎆 Please tell me if any changes need to be made before this issue can be closed.

TheBlackRoom commented 3 years ago

Sorry, I've been away from my desk for a while and will be again tomorrow. I'll do a quick test in a minute and let you know the results ASAP.

TheBlackRoom commented 3 years ago

So, I've downloaded the latest from Mozilla Add-ons (2.3) and unfortunately the only thing that seems to work is Alt-k (switch between/go to last played).

All the tabs continue to play no matter what combination of options I select or toggle.

Alt-q (fast forward) doesn't seems to work, neither does Alt-r (toggle auto resume). I have no idea about Alt-o but it seesm to do nothing but is probably affected by the other toggles.

You had things working in the last github one, but all that seems to have gone now.

Hope it's something obvious that you can fix.

Ah, I might just have worked out the issue - it seems that restarting Firefox gave me the clue in that my entry string in the "Places to use this extension" does not get saved between restarts so I think somehow that settings is having no effect (but somehow Alt-k is!)

NDevTK commented 3 years ago

The signed version keeps its permissions

TheBlackRoom commented 3 years ago

Hi, I wasn't sure what you meant by that ("The signed version keeps its permissions), but looking at the AutoPause Addon page in Firefox today I think there's been a silent update (with same version) as I now see the Alt-o version mention in the options page which I don't think was there before?

At first it still didn't seem to work, then I noticed the third tab (of FF Ad-on info) had permissions turned off. Setting that to "on" also didn't make any difference so I restarted Firefox and now it all seems to be working well.

Thanks for making this, to me it's now perfect and pauses nicely when many tabs are set to playing and then switching between them and resuming properly whenever going back. It also seems fine on the silent video tab - brilliant.

NDevTK commented 3 years ago

hopefully getting a fix for the muted media issue :D

TheBlackRoom commented 3 years ago

I think so, whatever that actually was - in my tests again just now I can't anything odd happening. I've flicked between various tabs with media playing and other tabs with no media present (preloaded or un-preloaded) and using my favourite option of "Pause media on tab change and limit resume to active tab" (which still is activated by Alt-i BTW), it all seems to work perfectly.

Sorry, I can't do the html/css for you, but for the options check/tick box description area you might want to indicate the keyboard shortcuts and maybe alter the descriptions, e.g.:

(add checkbox here) Disable auto-resume Previously playing tabs will not restart toggle = Alt-r

(add checkbox here) Play active tab only Pause/Resume on tab change Toggle = Alt-i

(add checkbox here) Continue play of tab when clicking to another (??? not sure of intended function of this one but this seems to happen for me) Alternate behaviour
No Toggle

Go to last used tab with audio or video Toggle = Alt+k

Play at 2x speed Fast Forward Toggle = Alt+q

Mark specific tab for auto-resume Only works when ??? - I'm not sure what this one does and it seems to vary or depend on the settings of the check boxes??? Toggle = Alt+o

I'm wondering if the three check-boxes (for the first three) actually ought to be Radio buttons, as their functions seem to be contradictory or mutually-exclusive???

NDevTK commented 3 years ago

The Resume multiple tabs (old behavior) and disable resume probably dont work together

NDevTK commented 3 years ago

Version 2.5

NDevTK commented 3 years ago

Thanks for your help