0

I am hoping someone can help me out with my problem im struggling to find a code to enable the autoplay video and audio at the same time in google chrome?

also this putting silence.mp3 is not working anymore on chrome.

<iframe src="./images/silence.mp3" allow="autoplay" id="audio" style="display:none" id="iframeAudio"></iframe><iframe src="./images/silence.mp3" allow="autoplay" id="audio" style="display:none" id="iframeAudio"></iframe>
<audio autoplay loop id="video_bg_plays" class="myaudio">
    <source src="./images/Wizard101_audio.mp3?autoplay=1&loop=1&muted=0" type="audio/mp3" >
</audio>
<div id="video_bg">
    <div style="background:url('./images/bg2.png') no-repeat top center;z-index:-3;position:absolute;width:100%;min-width:310px;height:100%" class="js-bg-video"></div>

    <video autoplay muted loop  id="video_bg_play" class="hide viewer">
        <source src="./images/Wizard101.mp4?autoplay=1&loop=1&muted=0" type="video/mp4">
    </video>
    <div class="player__controls">
       <!--<div class="progress">
        <div class="progress__filled"></div>
       </div>-->
       <button class="player__button toggle" title="Toggle Play">►</button>
       <!--<input type="range" name="volume" class="player__slider" min="0" max="1" step="0.05" value="1">
       <input type="range" name="playbackRate" class="player__slider" min="0.5" max="2" step="0.1" value="1">
       <button data-skip="-10" class="player__button">« 10s</button>
       <button data-skip="25" class="player__button">25s »</button>
     </div>-->
   </div>
</div>

1 Answers1

0

The only workaround I have found recently was below:

navigator.mediaDevices.getUserMedia({ audio: true }).then(function (stream) {
    var vid = document.getElementById("video_bg_plays");
    vid.play(); // play your media here then stop the stream when done below...
  
    stream.getTracks().forEach(function (track) { track.stop(); });
});

It will ask users for their Microphone permission and they have to click Allow once then you are permitted to play anything with sound. It works because as long as you are capturing then you are allowed to autoplay sound, without any user gesture needed.