Developers
How to use the internal audio player?
By default, when the Netvibes RSSReader displays and RSS feed with audio enclosures, it adds a Play button to those audio entries. Clicking that button opens the Netvibes Audio Player at the top of your Netvibes page. There, you can listen to the audio file, or “podcast”, while it loads, pause it, or click forward in the file playing.
You can make use of the Audio Player in your own widget, without having to resort to RSS enclosures. However, please note that the AudioPlayer currently only works within Netvibes.
The AudioPlayer object
The Netvibes internal audio player is available through the AudioPlayer object.
| Public methods | Description |
|---|---|
| play(fileUrl, title) | Plays fileURL with title as it's displayed name |
| pause() | Pauses the playing. Clicking Play resumes it |
| stop() | Stops the playing. Clicking Play restarts it |
| setOptions() | (soon to be implemented |
Using the audio player
Because the audio player is for now only available within the Netvibes environment, you have to check that the widget is indeed in Netvibes to make sure you are not calling a non-existent object.
if (AudioPlayer.play) { AudioPlayer.play(fileUrl, title); }
Sample code
Here is a sample code on how to build the button and make it call the audio player, with the audio stream's url being stored in the fileURL preference.
var MyWidget = {}; MyWidget.onLoad = function() { var a1 = document.createElement('span'); a1.style.display = 'inline'; a1.style.padding = '1px'; a1.style.cursor = 'pointer'; a1.innerHTML = '<img src="http://www.netvibes.com/img/speaker.gif" title="'Play'" />'; a1.onclick = function(event) { if (AudioPlayer.play) { MyWidget.onClickPlay(); return false; } } widget.body.appendChild(a1); // similar code for the Pause and Stop buttons, if necessary widget.callback('onUpdateBody'); } MyWidget.onClickPlay = function() { AudioPlayer.play(widget.getValue('fileURL'), 'This is my title'); }
Note that we only use return false if the AudioPlayer.play method is available - that is, if we are indeed within Netvibes. This way, on platforms other than Netvibes, the link would work and would either download the MP3 or the PLS file, letting the user choose which audio application he wants to use.
Live examples
The Web Radio Player widget is a complete widget which should help you understand how to build more complex podcasting widgets.
- Send to a friend
- Add to favorites
- Last modified: 2008/04/24 23:27

