-audio preview now works in firefox!! CC-1707

This commit is contained in:
martin 2011-01-31 00:50:33 -05:00
parent eeaa7da6f5
commit 815509eb70
7 changed files with 131 additions and 29 deletions

View file

@ -100,36 +100,49 @@ 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){
function getFileExt(filename){
return filename.split('.').pop();
}
var currentAudioPreviewID = "";
function audioPreview(filename, elemID){
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);
if (currentAudioPreviewID == elemID){
$('#jquery_jplayer_1').jPlayer('stop');
currentAudioPreviewID = "";
return;
} 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");
}
currentAudioPreviewID = elemID;
}
var ext = getFileExt(filename);
var uri = "/api/get-media/api_key/AAA/file/" + filename;
var media;
var supplied;
if (ext == "ogg"){
media = {oga:uri};
supplied = "oga";
} else {
media = {mp3:uri};
supplied = "mp3";
}
//$('#jquery_jplayer_1').jPlayer('stop');
$("#jquery_jplayer_1").jPlayer("destroy");
$("#jquery_jplayer_1").jPlayer({
ready: function () {
//alert(media);
$(this).jPlayer("setMedia", media).jPlayer("play");
},
swfPath: "/js/jplayer",
supplied: supplied
});
//$('#jquery_jplayer_1').jPlayer('setMedia', media).jPlayer('play');
$('#'+elemID).children("a").children().attr("class", "ui-icon ui-icon-pause");
}