Play sound in SO chat

I am trying to play a notification sound (or indicate a sound) in SO chat using the Chrome extension, but I can not understand it (if possible). I tried the following code:

this.notify = function () {
  $("#jplayer").jPlayer('play', 0);
}

But I get the following error:

Uncaught TypeError: Object [object Object] does not have a 'jPlayer' method

Can I use the SO chat sound module / player to play the @mention sound?

UPDATE

I know that I can set up my own “audio player”, but I want to use the audio player that is used in the chat here on SO, and I want to use a notification sound.

I uploaded my complete code to the github gist , which is part of this project . The line I'm trying to call the music player is 224 .

+5
source share
2 answers

My own sandbox, I think you are not allowed to execute scripts from the page, so I think the plugins are counting on.
It knew that it was just a matter of playing outside the sandbox ....

script.js

var customEvent = document.createEvent('Event');
customEvent.initEvent('JPlayerNotify', true, true);

function notify() {
    document.getElementById('communicationDIV').innerText='notify';
    document.getElementById('communicationDIV').dispatchEvent(customEvent);
}

// Utitlity function to append some js into the page, so it runs in the context of the page
function appendScript(file) {
    var script = document.createElement('script');
    script.setAttribute("type", "application/javascript");
    script.setAttribute("src", chrome.extension.getURL(file));
    document.head.appendChild(script);
}

appendScript("JPlayer.js");

// had to wait for a bit for the page to be ready (dialup and all), you wont need to do the setTimeout
setTimeout("notify()",3500);

JPlayer.js

var notify_node = document.createElement('div');
notify_node.id = 'communicationDIV';
document.documentElement.appendChild(notify_node);

notify_node.addEventListener('JPlayerNotify', function() {
  var eventData = notify_node.innerText;
  if (eventData=='notify'){
    $("#jplayer").jPlayer('play', 0);
  }
});

manifest.json

{
  "name": "JPlayerNotify",
  "version": "0.5.0",
  "description": "JPlayerNotify",
  "content_scripts" : [
    {
      "matches": ["http://chat.stackoverflow.com/rooms/*"],
      "js" : ["script.js"],
      "run_at" : "document_idle",
      "all_frames" : false
    }
  ],
  "permissions": [
    "http://stackoverflow.com/*",
    "https://stackoverflow.com/*",
    "http://*.stackoverflow.com/*",
    "https://*.stackoverflow.com/*"
  ]
}

You can see some things when communicating with the page here ... http://code.google.com/chrome/extensions/content_scripts.html

+3
source

Why not just:

new Audio('beep.wav').play();

Chrome ( ), . , .

+3

All Articles