How can i play sound in chrome extension

This question already has an answer here:

  • Insert an image in chrome extension 1 answer

  • 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() .

    链接地址: http://www.djcxy.com/p/82930.html

    上一篇: 我可以在Swift中将元类对象转换为协议类型吗?

    下一篇: 我如何在Chrome扩展中播放声音