0

I am using a jquery code to automatically run the video on desktops, with all versions of safari on mac it works except the the latest one which is high sierra, i am trying every possible combination to run it, no matter how apple sees it,

I had the code which mostly works

function startVideoIfNotStarted () {
     window.setTimeout(function(){
        var play = document.getElementById("player");
        play.addEventListener("load",function(){
            player.play();
        })
     }, 800);

    }
  startVideoIfNotStarted();

Now i am trying to use the click event to trigger itself but i am little bit confused on the code how should i do

setTimeout(function() {
            var play = document.getElementById("player");
            play.addEventListener("click",function(){
                player.play();
            })
         }, 1000);
  • 1
    Do you have autoplay disabled? Safari > Preferences > Websites > Auto-Play. Also, please do not auto-play video. – ordonezalex Nov 03 '17 at 17:23
  • i had to, its a requirement of client –  Nov 03 '17 at 17:25
  • Not sure what kind of video you got going here – whether it's an embed from YouTube for Vimeo or whatever, or if it's an HTML5 `video` tag – but in the latter case, check out [this question](https://stackoverflow.com/questions/13864795/wait-until-an-html5-video-loads). The `loadeddata` event in combination with an `autoplay` attribute on the video tag itself helped me solve this exact same problem last week. – cjl750 Nov 03 '17 at 21:45

1 Answers1

0

Not exactly sure what you're looking to do, but if you're trying to simulate a click on the video to play it, you could try something like:

$(document).ready(function(){
    $('#player').trigger('click'); 
    //handle the click event
    $('#player').on('click',function(){
        play(); //or whatever you're trying to accomplish here
    });
});

If it's anything like a youtube video, just triggering the click on it should play it I believe?

acaputo
  • 190
  • 12