user1159270
user1159270

Reputation: 29

How to play audio from a Google Chrome extension even when closed?

I've been making a Google Chrome extension, one that streams an audio file from another site. I use a Google audio player to do this, and it works fine.

The only problem is, the soundtrack stops playing when I leave the extension is closed. Right now, I don't use Java and would prefer to keep it that way, since I have about zero experience in that field. If I need to, I am perfectly willing to use it.

<embed type="application/x-shockwave-flash" flashvars="audioUrl=AUDIO URL HERE" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="400" height="27" quality="best"></embed>

This is what I'm using to play my audio files. I need to somehow get this to keep playing in the background page. I've tried making the main background page and the popup page the same; doesn't work. Here's my manifest file, with the popup and background pages one and the same:

"background_page": "Main Code.html",
    "permissions": [
      "background"
],
    "icons" : {
        "16" : "KH icon_16.png",
        "48" : "KH icon_48.png",
        "128": "KH icon_128.png"},
    "browser_action" : {
        "default_icon" : "KH icon_19.png",
        "default_popup": "Main Code.html"

Please help me, I've scoured the web for info on this, and being an amateur programmer, I really need help.

Upvotes: 2

Views: 5082

Answers (2)

Ishan
Ishan

Reputation: 3395

From what I seem to understand. Your problem is that as soon as you leave the extension the audio stops playing. I would suggest that you instead of using background_page, you should add a background script. Use Manifest version 2. Add a background script like this.

"background":
{
    "scripts": ["background.js"]
}

play your audio files through this background script.

I think this will solve your problem.

Upvotes: 3

jjNford
jjNford

Reputation: 5270

Um... I think you mean Javascript and not Java (2 completely different languages - not related in any way what so ever). Next you should get rid of all the spaces in your file names, not only is this terrible practice but your manifest is probably having trouble identify all of the the extensions components.

Finally... It may work to play the audio from the background page. Refer to the Google Chrome Extensions API for what a background page is. The code on the popup is not going to be the same as the code in the background page. To talk between the two refer to the chrome.extension.* package API. For a quick solution here is a socket utility that provides two way communication.

Upvotes: 0

Related Questions