YePpHa / YouTubeCenter

YouTube Center is a userscript designed to expand the functionality of YouTube. It includes the ability to download the video you're watching, auto selecting your preferred video quality and much more.
MIT License
2.89k stars 520 forks source link

Prevent autoplay plays video a couple of seconds before pausing #871

Open tyilo opened 10 years ago

tyilo commented 10 years ago

The reason I use the prevent autoplay options is so that I can open a bunch of videos from my subscriptions and then watch them all.

However when I open a video I have to wait around 5 seconds before the video pauses and so I get audio from a lot of videos at the same time.

Would it be possible either to make the pausing instant? If not, could you mute the audio, do the pausing and then unmute the audio again?

ViperCode7 commented 10 years ago

Actually, this is a bug. It used to work instantly, and when using aggresive flash it would bypass the HTML5 issue.

I've posted this issue some months ago but it hasn't been resolved.

The problem is the same HTML5 player starting early, then YTC pauses and loads Flash.

Running YTC with Tampermonkey in Chrome 36, issue happens only when loading clips in the background tab, not when using current tab to view one clip.

ghost commented 10 years ago

Another suggestion to solve this problem. is to give videos few seconds before "Only one player instance playing" activates. because almost always, when "Only one player instance playing" is checked. and i open a couple of videos in the background, the video i'm watching in the focused tab stops too, because a second or two start playing in the other videos before "stop auto-playing" activates.

BrokenCuckooClock commented 10 years ago

Didn't have this issue when I was still on 2.1, then updated to get the download button back and this problem reared its ugly head... very annoying.

ViperCode7 commented 10 years ago

Well, a lot has changed since then. As a side note, the youtube button is a reason why YTC is not accepted into Google's Webstore, making it easier to deliver the CRX version. This download button, while convenient, it's kinda pointless. There's the youtube-dl project going on and they are snappy at updates and all works flawlessly, paste the link, pick the quality and done.

The reason behind the issue might be the processing time YTC takes to load everything and process it all, when the HTML5 player might be a little faster, it loads early, YTC won't have time to interfere with its startup event.

A CRX might be faster vs. a TamperMoneky loaded user.js, add to that the more features YTC has, the bulkier the task stack gets. I'll have to do some speed testings and see if direct extension and disabling some features might improve YTC's loading times.

Endriel commented 9 years ago

nothing new about this? its realy annoying.

ViperCode7 commented 9 years ago

It's unfixable by YTC... I believe.

I use Disable Youtube HTML5 Player extension which fires a little faster and manages to prevent the pages from starting any HTML5 videos after which YTC takes over.

Endriel commented 9 years ago

"Stop YouTube HTML5 Autoplay" (chrome) works fine. thanks

tyilo commented 9 years ago

It's unfixable It's hard etc.

Here is a userscript I just made that does work and it's only a couple of lines:

// ==UserScript==
// @name         YouTube fix
// @namespace    tyilo
// @version      0.1
// @description  enter something useful
// @author       You
// @match        https://www.youtube.com/watch?v=*
// @grant        none
// @run-at       document-start
// ==/UserScript==
var plays = 0;
var originalPlay = HTMLVideoElement.prototype.play
HTMLVideoElement.prototype.play = function() {
    plays++;
    if(plays === 1) {
        return;
    } else {
        originalPlay.apply(this, arguments);
    }
};
ViperCode7 commented 9 years ago

Well Bob, what you did there is kinda what Disable Youtube HTML5 Player does, it messes with the HTML5 video playback of the browser. That, Bob, is not a fix, it's more or less a workaround.

A fix, is to make YTC not play HTML5 videos when we don't want them to play or play them when we do, without messing HTML5, as in retain HTML5 functionality.

For now, Disable Youtube HTML5 Player and its canPlayType prototype works fine. But your input is appreciated.

tyilo commented 9 years ago

But you could easily change plays === 1 to plays === 1 && shouldYTCStopAutoplayForHTML5Player().

If you still think that is a "hack", then YTC must be a large collection of hacks, so I don't see the problem really.

3ICE commented 9 years ago

Prevent background tab autoplay takes up to 5 seconds for me to go into effect. So when I open 6-10 videos in new tabs, I get a cacophony of overlapping audio and some amount of lag until all tabs are processed and — eventually — stopped.

YePpHa commented 9 years ago

It's possible that by changing the prototype of the video element could work. I will have to experiment with this.

Fironet commented 7 years ago

It's strange, as I'd never experienced this issue until this year when Youtube rolled out their new design (even though currently I'm in the 'opt out' mode).

Previously would work as expected but now around 2/3 videos play a few seconds, which with my loud speaker volume and the resetting of YT's volume each browser session on Firefox makes for sudden bursts of loud video intros before I have time to mute or adjust the volume 😩 (Youtube's previous 'Play' video UI overlay used to display the volume bar but now it's all hidden until the Play button is clicked leaving little time to adjust the volume, unfortunately).

I should mention that I've tried setting the volume via YTC's Player>Volume settings but it doesn't appear to work on either YT pages or embedded videos. If that worked it would be stupendous.