How can i play sound in chrome extension
This question already has an answer here:
The easiest way to play some sound/music using Javascript is by using an Audio
object: you just need to have the file you want to play inside your extension folder, and you can play it like this:
var myAudio = new Audio(); // create the audio object
myAudio.src = "path/to/file.mp3"; // assign the audio file to its src
myAudio.play(); // play the music
You can play using play()
and pause using pause()
.
下一篇: 我如何在Chrome扩展中播放声音