How to play audio using javascript?

Today, We want to share with you play audio javascript.In this post we will show you javascript audio stop, hear for audio html we will give you demo and example for implement.In this post, we will learn about Download Play Mp3 Music with an example.

Playing Music using JavaScript

play sound javascript

var audio = new Audio("hindi/Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3");
audio.play();

play audio in javascripts

var audio = new Audio('Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3');
audio.play();

play audio javascripts

var bMusic = new Audio('Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3')
	bMusic.play()

play a sound wiith js

var audio = new Audio('Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3');
audio.play();

play sound in javascript

<script>
function play() {
  var audio = new Audio('https://www.yourdomainname.net/media/hinndi/Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3');
  audio.play();
}
</script>
<button onclick-"play();">PLAY MY AUDIO</button>

javascript play audio

//play audio with from html audio element: 
document.getElementById('song_name').play();

//play audio with out html audio tag
var myAudio = new Audio('Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3');
myAudio.play();

<audio controls>
<source src="Agar_Tum_Saath_Ho_FULL_AUDIO_Song.ogg" type="audio/ogg">
<source src="Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3" type="audio/mpeg">

</audio>

The following is a sample script that can play a song_name file.

<audio controls id="song_name">
<source src="Agar_Tum_Saath_Ho_FULL_AUDIO_Song.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

<p>Click the buttons to play or pause the song_name.</p>

<button onclick="play()" type="button">Play </button>
<button onclick="pause()" type="button">Pause</button>

<script>
var fetchSongNm= document.getElementById("song_name");
function play() {
fetchSongNm.play();
}

function pause() {
fetchSongNm.pause();
}
</script>

I hope you get an idea about javascript play sound onclick.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Remove HTML Table Row and Column using jQuery

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Simple LocalStorage SessionStorage using JavaScript
  2. Read Also:  Bootstrap Multiple Item Product Carousel slider
  3. Read Also:  remove special characters from string php
  4. Read Also:  PHP Upload and Crop Image using jQuery Ajax
  5. Read Also:  how to delete (splice) an element from nested JSON using Vuejs
  6. Read Also:  jQuery Ajax Bootstrap Table Pagination using PHP MySQLi
  7. Read Also:  PHP Laravel 6 DataTables Tutorial
  8. Read Also:  how to make a login page in html with database?
  9. Read Also:  Custom jQuery Validate Validation Example | jquery validator.addmethod
  10. Read Also:  how to delete (splice) an element from nested JSON using Vuejs
CLOSEX