How to Auto-Play and Loop Audio and Video files in Android?

Applies to:
Product General
Platform Android

The Auto-play and Loop functions in Android is disabled to minimize the user bandwidth however this post may offer you some help if trying to find a quick fix for this problem.

All you  have to do is to follow following two easy steps.

1. Use following script for your HTML file –

function onPageLoad()
{
loadVideo();
loadAudio();
}

function loadVideo()
{
document.getElementById(“sampleVideo”).src = “./surefox.mp4”;
document.getElementById(“sampleVideo”).load();
startPlayingvideo();
}

function loadAudio()
{
document.getElementById(“sampleAudio”).src = “./surefox.mp3”;
document.getElementById(“sampleAudio”).load();
startPlayingaudio();
}

function startPlayingaudio()
{
//Keep looping the same audio
setTimeout(function() { document.getElementById(“sampleAudio”).play(); },100);
}
function startPlayingvideo()
{
//Keep looping the same Video
setTimeout(function() { document.getElementById(“sampleVideo”).play(); },100);
}

Note – Change the name of the audio and video file accordingly and make necessary changes if using only video or only audio files.

2. For the body of the HTML file, use following –

<body onload=”onPageLoad()”>
<div style=”width:10px;height:310px;padding:5px;”>
<video id=”sampleVideo” style=”width:300px;height:300px;” controls=”controls” onended=”startPlayingvideo()” ></video>
<audio id=”sampleAudio” style=”width:300px;height:300px;” controls=”controls” onended=”startPlayingaudio()” ></audio>
</div>
</body>

For quick check, download a sample file by clicking click here.

For any questions, do feel free to reach us on  techsupport@42gears.com.


2 Comments

  1. commentor on Thursday April 3rd, 2014 at 04:01 AM

    sample file did not work on android 4.2.2

    • bishal on Thursday April 3rd, 2014 at 11:22 AM

      Please use the new sample files in the post or reach out to our support team – techsupport@42gears.com who would be more than happy to assist you.

Leave a Comment