How to make chromium auto play a video with sound

408 views Asked by At

I am trying to make a simple page that plays auto plays videos in a loop. I have got it auto playing muliple videos with the below however I cannot get it to play with sound on Chromium broswer no matter what I do. I really need the sound to play. I have tried a few solutions with Iframes but I cant seem to get it to work. Please help



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Display - Poster Boxes </title>
    <link rel="stylesheet" href="css/main.css">
    
</head>
<body>


<audio autoplay loop  id="playAudio">
    <source src="audio/source.mp3">
</audio>

 <video muted autoplay onended="run()"  class="fullscreen-video" id="homevideo">
            <source src="video1.mp4" type="video/mp4">
            Your browser does not support HTML5 video.
          </video> 

<script>


video_count =1;
videoPlayer = document.getElementById("homevideo");

function run(){
        video_count++;
        if (video_count == 3) video_count = 1;
        var nextVideo = "video"+video_count+".mp4";
        videoPlayer.src = nextVideo;
        videoPlayer.play();
   };
   </script>
</body>
</html>





<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Omniplex Display - Poster Boxes </title>
    <link rel="stylesheet" href="css/main.css">
    
</head>
<body>


<audio autoplay loop  id="playAudio">
    <source src="audio/source.mp3">
</audio>

 <video muted autoplay onended="run()"  class="fullscreen-video" id="homevideo">
            <source src="video1.mp4" type="video/mp4">
            Your browser does not support HTML5 video.
          </video> 

<script>


video_count =1;
videoPlayer = document.getElementById("homevideo");

function run(){
        video_count++;
        if (video_count == 3) video_count = 1;
        var nextVideo = "video"+video_count+".mp4";
        videoPlayer.src = nextVideo;
        videoPlayer.play();
   };
   </script>
</body>
</html>



1

There are 1 answers

0
rustam On

you have to add type in source type="audio/mp3" example :

<audio autoplay loop  id="playAudio">
<source src="audio/source.mp3" type="audio/mp3">
</audio>

or you can see an example of using the audio tag https://www.w3schools.com/tags/att_audio_autoplay.asp