-added support to preview mp3+ogg audio (chrome only so far).

This commit is contained in:
martin 2011-01-28 16:32:38 -05:00
parent c673b12046
commit 6651688940
4 changed files with 39 additions and 5 deletions

View file

@ -95,4 +95,38 @@ function convertDateToPosixTime(s){
}
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");
}
}
}