sintonia/public/js/playlist/helperfunctions.js

133 lines
3.8 KiB
JavaScript

/* Takes an input parameter of milliseconds and converts these into
* the format HH:MM:SS */
function convertToHHMMSS(timeInMS){
var time = parseInt(timeInMS);
var hours = parseInt(time / 3600000);
time -= 3600000*hours;
var minutes = parseInt(time / 60000);
time -= 60000*minutes;
var seconds = parseInt(time / 1000);
hours = hours.toString();
minutes = minutes.toString();
seconds = seconds.toString();
if (hours.length == 1)
hours = "0" + hours;
if (minutes.length == 1)
minutes = "0" + minutes;
if (seconds.length == 1)
seconds = "0" + seconds;
if (hours == "00")
return minutes + ":" + seconds;
else
return "" + hours + ":" + minutes + ":" + seconds;
}
function convertToHHMMSSmm(timeInMS){
var time = parseInt(timeInMS);
var hours = parseInt(time / 3600000);
time -= 3600000*hours;
var minutes = parseInt(time / 60000);
time -= 60000*minutes;
var seconds = parseInt(time / 1000);
time -= 1000*seconds;
var ms = parseInt(time);
hours = hours.toString();
minutes = minutes.toString();
seconds = seconds.toString();
ms = ms.toString();
if (hours.length == 1)
hours = "0" + hours;
if (minutes.length == 1)
minutes = "0" + minutes;
if (seconds.length == 1)
seconds = "0" + seconds;
if (ms.length == 3)
ms = ms.substring(0, 2);
else if (ms.length == 2)
ms = "0" + ms.substring(0,1);
else if (ms.length == 1)
ms = "00";
if (hours == "00")
return minutes + ":" + seconds + "." + ms;
else
return "" + hours + ":" + minutes + ":" + seconds+ "." + ms;
}
function convertDateToHHMMSS(epochTime){
var d = new Date(epochTime);
var hours = d.getUTCHours().toString();
var minutes = d.getUTCMinutes().toString();
var seconds = d.getUTCSeconds().toString();
if (hours.length == 1)
hours = "0" + hours;
if (minutes.length == 1)
minutes = "0" + minutes;
if (seconds.length == 1)
seconds = "0" + seconds;
return "" + hours + ":" + minutes + ":" + seconds;
}
function convertDateToPosixTime(s){
var year = s.substring(0, 4);
var month = s.substring(5, 7);
var day = s.substring(8, 10);
var hour = s.substring(11, 13);
var minute = s.substring(14, 16);
var sec = s.substring(17, 19);
var msec = 0;
if (s.length >= 20){
msec = s.substring(20);
}
return Date.UTC(year, month, day, hour, minute, sec, msec);
}
/* This function decides whether a song should be played or stopped.
* It decides the current state of music through the presence/absence
* of the <audio> tag. It also takes care of the managing the play/pause
* icons of the buttons. */
function audioPreview(e, uri){
var elems = $('.ui-icon.ui-icon-pause');
elems.attr("class", "ui-icon ui-icon-play");
var s = $('#'+e);
var spl = $('#side_playlist');
if (spl.children('audio').length != 1){
spl.append('<audio autoplay="autoplay"></audio>');
//spl.children('audio').attr('autoplay', 'autoplay');
spl.children('audio').attr('src', uri);
var arr = $(s).children("a").children().attr("class", "ui-icon ui-icon-pause");
var myAudio = spl.children('audio')[0];
var canPlayMp3 = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/mpeg');
var canPlayOgg = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"');
alert(canPlayMp3);
alert(canPlayOgg);
} else {
if (spl.children('audio').attr('data-playlist-id') == $(s).attr("id")){
spl.children("audio").remove();
} else {
spl.children('audio').attr('autoplay', 'autoplay');
spl.children('audio').attr('src', uri);
spl.children('audio').attr('data-playlist-id', $(s).attr("id"));
$(s).children("a").children().attr("class", "ui-icon ui-icon-pause");
}
}
}