librefm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Librefm-commits] [1473] Improve the documentation of the javascript pla


From: Michael Sheldon
Subject: [Librefm-commits] [1473] Improve the documentation of the javascript player
Date: Sun, 10 May 2009 15:07:40 +0000

Revision: 1473
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1473
Author:   elleo
Date:     2009-05-10 15:07:40 +0000 (Sun, 10 May 2009)
Log Message:
-----------
Improve the documentation of the javascript player

Modified Paths:
--------------
    trunk/nixtape/js/player.js

Modified: trunk/nixtape/js/player.js
===================================================================
--- trunk/nixtape/js/player.js  2009-05-10 15:01:04 UTC (rev 1472)
+++ trunk/nixtape/js/player.js  2009-05-10 15:07:40 UTC (rev 1473)
@@ -30,6 +30,13 @@
 var playable_songs = false;
 var streaming = false;
 
+/**
+ * Initialises the javascript player (player.tpl must also be included on the 
target page)
+ * 
+ * @param array list A playlist in the form ([artist, album, track, trackurl], 
[...]) or false if playing a radio stream
+ * @param string sk Scrobble session key or false if the user isn't logged in
+ * @param string rk Radio session key or false if streaming isn't required
+ */
 function playerInit(list, sk, rk) {
        var audio = document.getElementById("audio");
        if (!list) {
@@ -58,6 +65,9 @@
        }
 }
 
+/**
+ * Finishes the player initialisation when the playlist has been loaded
+ */
 function playerReady() {
        var audio = document.getElementById("audio");
        
@@ -75,6 +85,9 @@
        player_ready = true;
 }
 
+/**
+ * Begins playback
+ */
 function play() {
        var audio = document.getElementById("audio");
        audio.play();
@@ -87,6 +100,9 @@
        $("#seekback").fadeTo("normal", 1);
 }
 
+/**
+ * Pauses playback
+ */
 function pause() {
        var audio = document.getElementById("audio");
        audio.pause();
@@ -96,16 +112,25 @@
        $("#seekback").fadeTo("normal", 0.5);
 }
 
+/**
+ * Seeks backwards 10 seconds in the current song
+ */
 function seekBack() {
        var audio = document.getElementById("audio");
        audio.currentTime = audio.currentTime - 10;
 }
 
+/**
+ * Seeks forwards 10 seconds in the current song
+ */
 function seekForward() {
        var audio = document.getElementById("audio");
        audio.currentTime = audio.currentTime + 10;
 }
 
+/**
+ * Updates the progress bar every 900 milliseconds
+ */
 function updateProgress() {
        var audio = document.getElementById("audio");
        if (audio.duration > 0) {
@@ -119,6 +144,9 @@
        setTimeout("updateProgress()", 900)
 }
 
+/**
+ * Called automatically when a song finished. Loads the next song if there is 
one
+ */
 function songEnded() {
        var audio = document.getElementById("audio");
        if(current_song == playlist.length - 1) {
@@ -129,6 +157,9 @@
        }
 }
 
+/**
+ * Outputs the HTML playlist
+ */
 function populatePlaylist() {
        var i, url;
        //Clear the list
@@ -146,12 +177,21 @@
        $("#song-" + current_song).css({fontWeight : "bold"});
 }
 
+/**
+ * Shows/Hides the HTML playlist display
+ */
 function togglePlaylist() {
        $("#playlist").toggle(1000);
        $("#showplaylist").toggle();
        $("#hideplaylist").toggle();
 }
 
+/**
+ * Submits a scrobble for the current song if a scrobble session key has been 
+ * provided. Makes use of a simple proxy to support installations where the
+ * gnukebox installation is at a different domain/sub-domain to the nixtape 
+ * installation.
+ */
 function scrobble() {
        var timestamp;
        scrobbled = true;
@@ -171,6 +211,10 @@
                        }, "text");
 }
 
+/**
+ * Submits 'now playing' data to the gnukebox server. Like scrobble() this 
+ * makes use of a proxy.
+ */
 function nowPlaying() {
        var timestamp;
        var audio = document.getElementById("audio");
@@ -183,12 +227,22 @@
        $.post("/scrobble-proxy.php?method=nowplaying", { "a" : artist, "b" : 
album, "t" : track, "l" : audio.duration, "s" : session_key}, function(data) 
{}, "text");
 }
 
+/**
+ * Loads a song and beings playing it.
+ * 
+ * @param int song The song number in the playlist that should be played
+ */
 function playSong(song) {
        var audio = document.getElementById("audio");
        loadSong(song);
        play();
 }
 
+/**
+ * Loads a song
+ *
+ * @param int song The song number in the playlist that should be loaded
+ */
 function loadSong(song) {
        var url = playlist[song]["url"];
        var audio = document.getElementById("audio");
@@ -227,6 +281,11 @@
        $("#trackinfo > #trackname").text(track);
 }
 
+/**
+ * Retrieves a playlist from the radio streaming service. 
+ * A radio session key must be supplied when initialising
+ * the play for this to work.
+ */
 function getRadioPlaylist() {
        var tracks, artist, album, title, url, i;
        $.get("/radio/xspf.php", {'sk' : radio_key, 'desktop' : 0}, 
function(data) { 
@@ -253,14 +312,26 @@
                }, "text");
 }
 
+/**
+ * Plays the song previous to the current one in the playlist
+ */
 function skipBack() {
        playSong(current_song - 1);
 }
 
+/**
+ * Plays the song after the current one in the playlist
+ */
 function skipForward() {
        playSong(current_song + 1);
 }
 
+/**
+ * Converts a timestamp to "MM:SS" format.
+ *
+ * @param int timestamp A timestamp in seconds.
+ * @return string The provided time in "MM:SS" format
+ */
 function friendlyTime(timestamp) {
        mins = Math.floor(timestamp / 60);
        sec = String(Math.floor(timestamp % 60));





reply via email to

[Prev in Thread] Current Thread [Next in Thread]