1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do youtube videos start playing automatically

Discussion in 'JavaScript' started by JEET, Jul 15, 2020.

  1. #1
    How do youtube videos start playing automatically

    When I have a <video> tag in my webpage, the video will not start playing automatically in safari and chrome.
    It plays automatically for FB and youtube though.
    I found this article:
    https://www.howtogeek.com/326532/sa...s.-heres-how-to-allow-them-for-certain-sites/

    Is there a shortcut way to give a javascript option to the user so that they will not have to edit those settings manually?
    Like they click a button on my website, and that above mentioned setting in the article is made for them by my website?

    That way when they return to my website in future then videos will play automatically.

    I think this is a very bad thing Apple and Google are doing, showing bias towards their own websites, or biased towards the websites which pay them a hefty fee for this behaviour...
    If this setting is not auto allowed for us, it should not be allowed for those sites also.
     
    JEET, Jul 15, 2020 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    598
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    wmtips, Jul 15, 2020 IP
    JEET and qwikad.com like this.
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #3
    BTW if you want your video to autoplay with sound muted you can add &mute=1
     
    qwikad.com, Jul 15, 2020 IP
    JEET likes this.
  4. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    qwikad.com
    What is the point of that video, no sound...

    wmtips
    I am not talking about embedded videos from youtube.

    I am saying if someone uploads a video on my site, and I have set autoplay to on in the video, still iphone ipad etc and even chrome/safari browsers will not autoplay the video.
    Autoplay is on, still.

    Here's an example:
    https://www.hashkaro.com/topic/3253/Cricket-Joke-Video

    Open that page in firefox first, then in chrome/safari.
    Video will start autoplaying in firefox, but this will "not" happen in chrome/safari.
    Then if you open some video, any video on youtube, it will autoplay in both those browsers which are restricting other websites from autoplay.

    This is my point.
    Seems like there is a setting in both those browsers which allows certain websites to autoplay videos. (which is biased behaviour according to me)

    My question is,
    how do I enable that setting "easily" for users of my website.
    So if someone comes to my website, I show them a button saying, "Auto play videos on this website".
    User clicks it, and that setting gets turned on for my site.
    So next time when user opens a video on my site, video plays automatically.
     
    JEET, Jul 15, 2020 IP
  5. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #5
    Are you saying you have never gotten freaked out by a loud sound while visiting a site? I have. Note that a few social media sites mute their videos by default. I believe it's done for that very reason. I prefer the option where I can manually turn the sound on.
     
    qwikad.com, Jul 15, 2020 IP
    JEET likes this.
  6. hdewantara

    hdewantara Well-Known Member

    Messages:
    536
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #6
    hdewantara, Jul 15, 2020 IP
    JEET likes this.
  7. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #7
    qwikad.com
    Sure, that is irritating, but who is Apple or Google to block videos, but no block on their own sites?
    They do not want people to listen to loud sound, then reduce the volume, 10% 20% something.
    Completely blocking it or forcing developers to use muted is "bad/unfair business practice" by these companies because they are themselves running the same service and "not" blocking it on their websites.
    I have been to youtube, and have been irritated by high volume in the video playing... Its not blocked there. Default volume is also 100%.
    Its like you start using a browser made by Amazon which allows you to buy only from Amazon and not from eBay or "any" other website.
    This is what these people are doing now.
    Both these companies are doing "evil, pure evil" now, in the name of "helping surfers".

    Hdewantara,
    That won't help me or my users.
    My best option is to get my users to change the setting of the browser that controls which websites can autoplay videos, add my website to the list.
    And I cannot tell them to go into settings > allowed sites > etc etc...
    I'd need a quick button which does it automatically for them when they click it.
    Browser can show some confirmation yes/no etc, that is ok.
    Any ideas for this button?
     
    JEET, Jul 15, 2020 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    For all the dancing around in this thread, nobody is understanding your question, much less providing an answer.

    They use JavaScript to manually start it onload. Grab hold of the element, and Element.play it!

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play

    Doesn't work scripting off, OH WELL.

    That said, do NOT autoplay videos on pages, are you just TRYING to piss people off?
     
    deathshadow, Jul 17, 2020 IP
    JEET likes this.
  9. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #9
    @deathshadow
    Its still not working.
    Here's the URL which has video
    http://hashkaro.com/vidCheck.html

    When opened in Chrome, it will show a javascript "confirm" box, asking user to press "OK to PLAY".
    Even when ok is clicked, user interacted with the browser window, still the video will not start.
    See console for error generated.

    The function is triggered from <body onload=" eppAutoPlay() ">

    Here's the code:

    //try autoplay onload
    function eppAutoPlay(){
    if( document.getElementById("eppVideoFile")!=null ){
    aa=document.getElementById("eppVideoFile");
    console.log("length: "+ aa.currentTime);
    if( aa.currentTime <= 0 ){
    console.log("me trying to play video");
    p= confirm("Press OK to PLAY video");
    if(p==true){
    aa.play();
    }
    }//video not playing
    }//video is there
    }//func

    Is pressing an "OK" button not considered user interaction?

    No, not trying to piss people off, am trying to make things as easy as possible for my website users.
    They already know that the page they are going to open has a video, and am trying to make it start automatically so they do not have to look for the "play" button.
     
    Last edited: Jul 18, 2020
    JEET, Jul 17, 2020 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #10
    confirm is not a document interaction. You need to use an actual <button>. Might I suggest a modal dialog instead?

    Though really you're trying to circumvent browser options that exist to prevent pissing people off with auto-playing video. It's something good browsers do everything they can to prevent you from doing.

    You do have code issues though, like the use of onload in the markup instead of addEventListener, the "aa" variable lacking a declaration (var/let/const), unneccessary comparison operations (!=null, == true), the full script going full gungan being loaded in <head> instead of right before </body> where scripting belongs, some sort of junk screwing around with innerHTML (the hallmark of crappy scripting), a total lack of formatting making it harder to maintain, etc, etc.

    The HTML being no winner either, with outdated XHTML crap under a 5 document, outdated character encoding, attributes that have no business in any HTML written after 2003, static style in the markup, H3 around something that's clearly NOT a heading, etc, etc.

    Really though your idea of "easy for users" sounds sketchy. Another example of where I suspect I have a different definition of the word "easy". EASY for users would be them just clicking to start the video playing. Oh noes, they have to start the video manually, the default behavior on every site I can stomach, not that.

    Also you talk about auto-play on sites like YT which don't do that for me... Some sites like Netflix can do that, but only if you've launched the video from another page on the same domain. If you navigate straight to the URI they don't play.

    You're basically trying to circumvent a laundry list of conditions of when/where audio playback is allowed. See the google dev site on the topic:

    https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
     
    deathshadow, Jul 18, 2020 IP
    JEET likes this.
  11. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #11
    @deathshadow
    Reason autoplay is not working on netflix when you go to the site directly, is defined in this document on google's website:
    https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
    And this is 100%, 1 million percent, 1 billion percent wrong behaviour by google.
    Same page you linked to.

    These people have "altered" the natural behaviour of a HTML tag,
    and are not following the same policy for their own website.

    Its like they decide not to show bright red color on a HTML page, because it hurts eyes of people.
    And then go and design a whole website around red color themselves.
    Will you be ok with that kind of CSS behaviour?
    Every browser company deciding its own CSS behaviour for the same CSS syntax?

    HTML does not says that autoplay will be allowed on a particular domain if max content of that domain is video based.
    HTML says that its allowed for all, no matter what.

    Here is the HTML page which describes the "natural behaviour" of video/audio with "autoplay" setting:
    https://www.w3schools.com/tags/att_video_autoplay.asp
    If you don't trust w3schools website, you can find natural behaviour of "autoplay" on any website of your choice, mozilla etc anything you want.
    It will still say that if autoplay attribute is set to true, then video/audio will start automatically.

    If browser companies are so sympathetic to the plight of the surfer,
    then block autoplay on youtube also,
    and give a notification to turn on the setting for the website user is currently on.
    Do the same for my site too, I have no problem.

    But when browser making company sets its own policy, blocks content of my website, and allows same content on their own operated website, then its 1 billion percent "unfair business practice".
     
    JEET, Jul 18, 2020 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #12
    Yes, I know, that's why I mentioned it. That way if you direct link, it's not going to piss people off, but if you navigate on-site it should work. Hence you should be able to have autoplay work if you put your video in an iframe on a sub-page and link to it from a main page.

    A tag that should NEVER have existed in the first place (it's redundant to object), should NEVER have even had the option to autoplay... etc, etc.

    What site is that? Do you mean YT? Cause that's not a thing. When you say:

    I've been on blink based browsers for near on a decade now, ever since I moved to Vivaldi when Opera told its faithful users to go F*** themselves. Auto-play on youtube is not a thing unless it's ajaxed in off an already playing playlist. Good gravy that would be horrifying given my browsing habits of middle clicking to open 10+ videos so I can watch them without having to go back to the originating page over and over.

    You mean like the options in vintage Opera that made shitty websites usable? So long as it's an OPTION I'm down with telling a site's designer to go F*** themselves. That's why I use stylus after-all... without which many websites are broken useless inaccessible crap. (See Digital Point)

    Something that should NEVER have been allowed in the first damned place, and just more proof -- like HGROUP -- showing that the dipshits at the WhatWG didn't know enough about usability, accessibility, or even the purpose of HTML to have been making 4 Strict's successor. It's painfully clear they have their cranium wedged up 1997's rectum, and the toothless W3C went full Gungan adopting their train wreck of "eye cans haz teh intarwebs" that is the bloated disaster they have the unmitigated GALL to call a "specification".

    That you're even pointing at W3Fools is a sure-fire indicator you need to go back and re-learn HTML from scratch. IF you think ANYTHING from them is good advice, you don't know enough about HTML, CSS, or JavaScript to even form a valid opinion on the topic. Those halfwit scam-artists are a blight upon learning anything.

    And whilst:
    Is entirely true, it's just more f***wit idiocy that this is even something that is allowed in the first place. It's one of the major things I would see stricken from HTML sooner than later... alongside all the pointless redundancies (audio, video), presentational concepts (aside), and general lack of failing to grasp the point of HTML. (user created tags much?)

    From a usability, accessibility, and simplicity standpoint HTML 5 is a ***ing shit-show. Which is why some browser makers are taking it upon themselves to fix things that never should have existed in the first place.

    Again, complaining about something that from where I'm sitting isn't even a thing. The only time I've seen anything resembling autoplay on youtube is when one video ends and the next auto-starts... be it Chrome, Vivaldi, OR Firefox... so I'm really not sure what you're even on about there.
     
    deathshadow, Jul 18, 2020 IP
    JEET likes this.
  13. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #13
    @deathshadow
    I am lost, not sure what you are saying when you say that youtube is not autoplaying videos.
    I went to this youtube video from a very old bookmark, plays automatically.

    Copy that link to clipboard, open new Chrome window, and open that URL, it will autoplay. Same will happen on Apple safari too.
    If its not autoplaying for you, then it means that you have turned autoplay off in your browser settings, which is 100% fine with me. That is your choice, not browser company's choice.

    Secondly, it does not matters if a tag should be there or not.
    Point is, the tag is there, and option of autoplay is also there.
    And both Google and Apple have blocked it, but kept it on their own website.


    Red color is an example.
    Suppose you use this in your CSS:
    #someDiv{
    float: left;
    }

    But the browser "hides" the div completely, or floats it to right, will you be ok with it, simply because browser company made a policy that they do not want items to float left?
    Even though its against CSS rules?
    Will you be ok with that?

    I am definitely not.
     
    JEET, Jul 18, 2020 IP
  14. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #14
    Let me try the iframe thing. Will let you know how it goes.
     
    JEET, Jul 18, 2020 IP
  15. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #15
    That YT video no matter how I access it? No autoplay in Chrome, FF, or Vivaldi... and both Chrome and FF are vanilla installs on purpose so I can test what other people get.

    You mentioned "The new IE" (aka Safari), does that mean you're on a quackintosh? If so, perhaps it's crApple's choices on supporting or not supporting things screwing with you.

    Maybe it's time to ask mommy and daddy if you can ditch the Fisher Price "My First Computer".

    That last part is not meant as an insult, it's a joke from an old ALT-CTRL-DEL comic from something like 15 years ago.
     
    deathshadow, Jul 18, 2020 IP
    JEET likes this.
  16. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #16
    @deathshadow
    Don't worry about insults, I like you a lot, will not mind a few friendly LOLS from you. Plus my overall resistance is not that low.

    No, I am not on MAC.
    My father uses iPhone and iPads, neither is autoplaying videos of my website, but are very comfortably autoplaying youtube videos.

    I don't know why those youtube videos are not autoplaying for you, because I know for sure that youtube videos autoplay as soon as a video page is opened, even on chrome.
    My chrome installation is the default I downloaded from google, installed it only to check websites during development, no other use of chrome for me.
    I checked it on a PC too, youtube video starts automatically there as well.

    There are tons of webpages online explaining to users how to turn off auto start/play on youtube, somehow google still thinks that autoplay on youtube is good.
    Likewise, there are tons of webpages online, asking how to autoplay video on other websites, somehow google still thinks that autoplay on other websites is not good.

    I honestly don't care what their policy is about autoplay videos.
    My whole point is, HTML allows <video autoplay src="some.mp4"></video>
    and even after doing this, my videos are not autoplaying on my website, because browser is choosing to block it.

    Its showing a clear message in console error, user interaction needed.
    This is "NOT" a requirement of HTML for autoplay videos, and these people have definitely altered the natural behaviour of the tag.

    LOL I just went to Chrome > help > About chrome, to find the version I got installed, and it started updating itself!
    What a super nice thing to do to annoy me!!!
    My chrome version is 83 by the way.
    Now version is 84.
    And youtube videos are definitely autoplaying on first hit to a youtube video page, no user interaction needed.
    100% biased business practice.
    Here is a youtube video link for you, close all other windows, open new chrome window, and copy paste this:

    youtube.com/watch?v=haslTsAS7oo

    (baby care video)

    I even came across stackoverflow answers last night, where members were giving each other methods on how to autoplay videos, and asking how is youtube doing this, and why is it not working on other websites.
    I don't know why its not autoplaying video for you. May be you added youtube.com to some other security zone or something, am not sure, but videos autostart on youtube for sure.
     
    JEET, Jul 18, 2020 IP
  17. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #17
    It has always been the case with YT. When you click the video icon of the video you want to watch it will start playing (on the page where the video is). Or if you copy and paste that link in the browser, the video will autoplay as well. I am not sure what the confusion is all about. Now if the video is posted somewhere else (let's say on DP) then it's not set to autoplay unless you add that option manually.
     
    qwikad.com, Jul 18, 2020 IP
    JEET likes this.
  18. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #18
    @qwikad.com
    Exactly my point too.
    Video is posted on digital point etc, digital point makes a iframe of it, embeds it, video does not plays automatically, that I understand.
    My point is not that.

    Suppose I give you a URL of youtube, page which has a video.
    You open that link in a completely new browser window on chrome,
    Video will start playing automatically.
    Exactly like how its intended to with: <video autoplay>
    This is how it has been since the start of youtube, even today its same.

    Now,
    I upload the same video to my website, lets say hashkaro.com
    and I share you a link to the video, in email or on whatsapp, or here on this forum.
    You click it, and video will not play, even with <video autoplay>
    When I try to start the video using javascript, still will not play, gives console error, user interaction needed.

    This is my entire point in this conversation,
    If autoplay is working for youtube, then why is it blocked for my website?
    This is not a bug either, its 100% bad business practice of Google.
    They are altering behaviour of HTML tags and even javascript using their web browser.
    And if altered behaviour was applicable to their website also, that I would understand.
    But there are 2 policies, one for youtube, and another one for you and me.

    Get my point now?

    Browsers are not supposed to modify the behaviour of HTML tags in the first place, no matter what.
    Browser company cannot make a particular HTML tag to behave differently from what its intended to.
    Both Apple and Google did this.

    Not just this,
    they retained original behaviour for their own websites, and "forced" new behaviour on us.

    I don't know how and why webmasters all around the world bowed down before this mafia/gangster rule.

    I intend to do something about this, either today or tomorrow, sooner or later, but I am definitely doing something about this mafia rule.
    Will not accept with silence...
     
    JEET, Jul 19, 2020 IP
  19. weavercrowds

    weavercrowds Peon

    Messages:
    5
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    3
    #19
    force autoplay video html youtube from embed tag working in browser firefox ubuntu
    <html>
    <head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><title>autoplay youtube weavercrowds</title>
    </head><body id="B"></body>
    <script>
    window["$_video"]=(...a)=>{
        var object=a[0];
        var videoembed=document.createElement("embed");
        videoembed.src=object.src;
        for(property in object.style){
            videoembed.style[property]=object.style[property];
        }
        object.parent.appendChild(videoembed);
        return videoembed;
    };
    
    var video_jajaja_espiral=$_video({parent:document.body,src:"https://www.youtube.com/embed/"+
        "lPVBrRd9wCo?autoplay=1",style:{position:"absol"+
        "ute",borderRadius:"50px",width:"300px",height:"300px",top:"10"+
        "0px",left:"100px",transform:"rotate(0deg)",transition:"all 1000s"}});
    
    window.onload=()=>{video_jajaja_espiral.style.transform="rotate(60000deg)";
    setInterval(()=>{console.log(eval("console.clear()"));},500);//a bug of w3c from linux in bash w3m browser from framebuffer video dev/media
    
    }
    
    
    </script>
    <body></body>
    </html>
    HTML:
    embed tag In -> ubuntu-firefox (working autoplay) , ubuntu-chromium(not working autoplay) , ubuntu-opera(not working autoplay)

    now with iframe properties

    <html>
    <head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><title>autoplay youtube weavercrowds</title>
    </head><body id="B"></body>
    <script>
    window["$_video"]=(...a)=>{
        var object=a[0];
       
        var videoembed=document.createElement("iframe");
        videoembed.frameborder="0";
        videoembed.allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture";
        videoembed.src=object.src;
        for(property in object.style){
            videoembed.style[property]=object.style[property];
        }
        object.parent.appendChild(videoembed);
        return videoembed;
    };
    
    var video_jajaja_espiral=$_video({parent:document.body,src:"https://www.youtube.com/embed/"+
        "lPVBrRd9wCo?autoplay=1",style:{position:"absol"+
        "ute",borderRadius:"50px",width:"300px",height:"300px",top:"10"+
        "0px",left:"100px",transform:"rotate(0deg)",transition:"all 1000s"}});
    
    window.onload=()=>{video_jajaja_espiral.style.transform="rotate(60000deg)";
       
        setInterval(()=>{console.log(eval("console.clear()"));},500);//a bug of w3c from linux in bash w3m browser from framebuffer video dev/media 
    }
    
    
    
    </script>
    <body></body>
    </html>
    Code (markup):
    works on all ubuntu-browsers except ubuntu-chromium

    but the cheat for to play a tag video semi-automatic is for example if mouse exists
    window["play"]="desactive";
    window.onmousemove=()=>{if(window["play"]=="desactive"){window["play"]="active";video.play();}};

    for example in touchscreens

    window["play"]="desactive";
    window.onorientationchange=()=>{if(window["play"]=="desactive"){window["play"]="active";video.play();}};
     
    Last edited: Jul 19, 2020
    weavercrowds, Jul 19, 2020 IP
    JEET likes this.
  20. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #20
    @weavercrowds
    My video is not hosted on youtube.
    Its hosted on my website itself.
     
    JEET, Jul 19, 2020 IP