Html5 Audio Stop Function

HTML5 Audio stop function

Instead of stop() you could try with:

sound.pause();
sound.currentTime = 0;

This should have the desired effect.

How to stop audio played by audio tag of HTML5

Try this:

  try
{
if(MyAudio != undefined)
{
MyAudio.pause();
}
MyAudio = new Audio("filename");
MyAudio.play();
}
catch(v)
{
//alert(v.message);
}

Javascript to stop playing sound when another starts

This is not very difficult to do if you use HTML5 which introduced the HTMLAudioElement.

Here is the minimal code for what you are trying to do:

// Let's create a soundboard module ("sb")var sb = {  song: null,  init: function () {    sb.song = new Audio();    sb.listeners();  },  listeners: function () {    $("button").click(sb.play);  },  play: function (e) {    sb.song.src = e.target.value;    sb.song.play();  }};
$(document).ready(sb.init);
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>Audio</title></head><body>  <button value="https://www.gnu.org/music/FreeSWSong.ogg">Song #1</button>  <button value="https://www.gnu.org/music/free-software-song-herzog.ogg">Song #2</button>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></body></html>

HTML5 - how to stop audio when another audio tag starts playing?

Ok, here is how I solved it:

The addEventListener grabs the audio beginning to play and the for loop pauses all other audio tags.

document.addEventListener('play', function(e) {
var audios = document.getElementsByTagName('audio');

for (var i = 0, len = audios.length; i < len; i++) {
if (audios[i] != e.target) {
audios[i].pause();
}
}
}, true);

How to pause or stop an HTML5 Audio element from component.ts

Call .pause() on the audio element.

stopAudio() {
this.audio.pause();
}

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement

HTML5 Audio Element is Restarting instead of Resuming using play(), pause()

The problem is that you override audio src when you pause and play again.

Try to check if src exists and it is the same was playing before paused it.

if(audio_pbar.src !== datasrc) audio_pbar.src=datasrc;

Sound Play / Stop / Pause

If you change that:

soundPlayer = new Audio(soundName).play();

To that:

soundPlayer = new Audio(soundName);
soundPlayer.play();

Your pause will be working. The problem is that you assigned "play" function to soundPlayer. SoundPlayer isnt an Audio object now.

Instead of stop() use:

soundPlayer.pause();
soundPlayer.currentTime = 0;

It works the same I guess.



Related Topics



Leave a reply



Submit