Jump to content

HTML5 audio tag. Play only last selected audio


carlosj

Recommended Posts

Hi,

 

I would like to solve a little but annoying detail on my site.

 

I am using the html5 <audio tag> to make a simple audio player that has several files and would love to be able to implement this little detail: I want it to stop the audio when any other file is selected to be played.

 

Right now if you hit play, and a preceding file is on play...well ... both sound at the same time. So I simply want to implement some kind of rule to play ONLY the last selected one. Is this possible?

 

Please have in mind that I am not a skillful programmer or any thing. I know just a enough to copy code here and there.

 

Thanks in advance to any one who could help me out.

 

Best regards.

Edited by carlosj
Link to comment
Share on other sites

<audio id="sample" src="sounds.mp3"></audio><a href="javascript:play1();">Play1</a><a href="javascript:play2();">Play2</a><a href="javascript:pauseAudio();">Pause</a><script>var audio = document.getElementById('click');function play1(){audio.currentTime = 0;audio.play();// This is the problem areaaudio.addEventListener('timeupdate', function (){if (currentTime >= 0.5) {audio.pause();}}, false);} function play2(){audio.currentTime = 0.5;audio.play();}function pause(){audio.pause();}</script>

 

it possible in javascript

http://stackoverflow.com/questions/5932412/html5-audio-how-to-play-only-a-selected-portion-of-an-audio-file-audio-sprite

 

 

go this link

Edited by harpalsinh999
Link to comment
Share on other sites

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><script type="text/javascript"><!--function song(){document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+document.getElementById('cancion').value+"' name='MediaPlayer1' width='300' height='70' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true'></embed>";}//--></script></head><body><div style="text-align:center;"><select name="" id="cancion" onchange="song()" size="1"><option value="none">::::::::::::: Choose Your Song Here :::::::::::::</option><option value="http://urltosong1.mp3">Song 1</option><option value="http://urltosong2.mp3">Song 2</option><option value="http://urltosong3.mp3">Song 3</option><option value="http://urltosong4.mp3">Song 4</option><option value="http://urltosong5.mp3">Song 5</option> </select><br><span id="music1"><embed type="application/x-mplayer2" id="music1"pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"src=""name="MediaPlayer1"width="300"height="70"controltype="2"showcontrols="1"showstatusbar="1"AutoStart="0"></embed></span></div></body></html>

Edited by harpalsinh999
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...