2.2.7 jplayer switch, shortcuts added

This commit is contained in:
Trevor Squillario 2012-10-30 14:40:21 -04:00
parent 015601641c
commit 7cb503201c
17 changed files with 696 additions and 400 deletions

View file

@ -9,7 +9,8 @@ function playSong(el, songid, albumid, position, loadonly) {
dataType: 'json',
timeout: 10000,
success: function (data) {
var title, artist, album, rating, starred, contenttype;
var title, artist, album, rating, starred, contenttype, suffix;
var specs = '';
if (data["subsonic-response"].directory.child !== undefined) {
// There is a bug in the API that doesn't return a JSON array for one artist
var children = [];
@ -27,6 +28,10 @@ function playSong(el, songid, albumid, position, loadonly) {
rating = child.userRating;
if (child.contentType == 'audio/ogg') { contenttype = child.contentType; } else { contenttype = 'audio/mp3'; }
if (child.starred !== undefined) { starred = true; } else { starred = false; }
if (child.bitRate !== undefined) { specs += child.bitRate + ' Kbps'; }
if (child.transcodedSuffix !== undefined) { specs += ', transcoding:' + child.suffix + ' > ' + child.transcodedSuffix; } else { specs += ', ' + child.suffix; }
if (child.transcodedSuffix !== undefined) { suffix = child.transcodedSuffix; } else { suffix = child.suffix; }
if (suffix == 'ogg') { suffix = 'oga'; }
}
});
}
@ -41,6 +46,7 @@ function playSong(el, songid, albumid, position, loadonly) {
$('#songdetails_song').attr('childid', songid);
$('#songdetails_artist').html(artist + ' - ' + album);
$('#songdetails_artist').attr('title', toHTML.un(artist + ' - ' + album));
$('#songdetails_specs').html(specs);
var coverartSrc, coverartFullSrc;
if (coverart == undefined) {
coverartSrc = 'images/albumdefault_56.jpg';
@ -53,128 +59,94 @@ function playSong(el, songid, albumid, position, loadonly) {
$('#coverartimage img').attr('src', coverartSrc);
$('#playermiddle').css('visibility', 'visible');
$('#songdetails').css('visibility', 'visible');
if (!loadonly) { // Sometimes we only want to load the track and not play
// SoundManager Initialize
var salt = Math.floor(Math.random() * 100000);
soundManager.onready(function () {
if (debug) {
console.log("SM HTML5 STATUS");
$.each(soundManager.html5, function (key, value) {
console.log(key + ': ' + value);
});
}
var sm = soundManager.getSoundById('audio');
if (typeof sm !== undefined) {
soundManager.destroySound('audio');
}
soundManager.createSound({
id: 'audio',
url: baseURL + '/stream.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&id=' + songid + '&salt=' + salt,
stream: true,
type: contenttype,
multiShot: false,
whileloading: function () {
//if (debug) { console.log('loaded:' + this.bytesLoaded + ' total:' + this.bytesTotal); }
var percent = this.bytesLoaded / this.bytesTotal;
var scrubber = $('#audio_wrapper0').find(".scrubber");
var loaded = $('#audio_wrapper0').find(".loaded");
loaded.css('width', (scrubber.get(0).offsetWidth * percent) + 'px');
loaded.attr('title', Math.round(percent * 100) + '% loaded');
},
whileplaying: function () {
//if (debug) { console.log('position:' + this.position + ' duration:' + this.duration); }
var percent = this.position / this.duration;
var scrubber = $('#audio_wrapper0').find(".scrubber");
var progress = $('#audio_wrapper0').find(".progress");
progress.css('width', (scrubber.get(0).offsetWidth * percent) + 'px');
var played = $('#audio_wrapper0').find(".played");
var p = (this.duration / 1000) * percent,
m = Math.floor(p / 60),
s = Math.floor(p % 60);
played.html((m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s);
// Scrobble song once percentage is reached
if (!scrobbled && p > 30 && (percent > 0.5 || p > 480)) {
if (debug) { console.log("LAST.FM SCROBBLE"); }
scrobbleSong(true);
}
},
onload: function () {
var duration = $('#audio_wrapper0').find(".duration");
var dp = this.duration / 1000,
dm = Math.floor(dp / 60),
ds = Math.floor(dp % 60);
duration.html((dm < 10 ? '0' : '') + dm + ':' + (ds < 10 ? '0' : '') + ds);
var scrubber = $('#audio_wrapper0').find(".scrubber");
scrubber.unbind("click");
scrubber.click(function (e) {
var x = (e.pageX - this.offsetLeft) / scrubber.width();
var position = Math.round(dp * 1000 * x);
var s = soundManager.getSoundById('audio');
s.setPosition(position);
// jPlayer Setup
var audioSolution = "html,flash";
if (getCookie('ForceFlash')) {
audioSolution = "flash,html";
}
$("#playdeck").jPlayer("destroy");
$("#playdeck").jPlayer({
swfPath: "js/jplayer",
wmode: "window",
solution: audioSolution,
supplied: suffix,
errorAlerts: debug,
warningAlerts: false,
volume: parseInt(volume)/100,
cssSelectorAncestor: "#player",
cssSelector: {
play: "#PlayTrack",
pause: "#PauseTrack",
seekBar: "#audiocontainer .scrubber",
playBar: "#audiocontainer .progress",
//mute: "#mute",
//unmute: "#unmute",
currentTime: "#played",
duration: "#duration"
},
ready: function () {
if (suffix == 'oga') {
$(this).jPlayer("setMedia", {
oga: baseURL + '/stream.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&id=' + songid + '&salt=' + salt,
});
scrubber.mouseover(function (e) {
$('.audiojs .scrubber').stop().animate({ height: '8px' });
} else if (suffix == 'mp3') {
$(this).jPlayer("setMedia", {
mp3: baseURL + '/stream.view?u=' + username + '&p=' + password + '&v=' + version + '&c=' + applicationName + '&id=' + songid + '&salt=' + salt,
});
scrubber.mouseout(function (e) {
$('.audiojs .scrubber').stop().animate({ height: '4px' });
});
},
onpause: function () {
if (debug) { console.log('Pause Event: ' + ' playState:' + this.playState + ', readyState:' + this.readyState + ', position:' + this.position + ', duration:' + this.duration + ', durationEstimate:' + this.durationEstimate + ', isBuffering:' + this.isBuffering); }
},
onresume: function () {
if (debug) { console.log('Resume Event: ' + ' playState:' + this.playState + ', readyState:' + this.readyState + ', position:' + this.position + ', duration:' + this.duration + ', durationEstimate:' + this.durationEstimate + ', isBuffering:' + this.isBuffering); }
},
onsuspend: function () {
if (debug) { console.log('Suspend Event: ' + ' playState:' + this.playState + ', readyState:' + this.readyState + ', position:' + this.position + ', duration:' + this.duration + ', durationEstimate:' + this.durationEstimate + ', isBuffering:' + this.isBuffering); }
},
onfinish: function () {
var next = $('#CurrentPlaylistContainer tr.playing').next();
if (!changeTrack(next)) {
if (getCookie('AutoPilot')) {
getRandomSongList('autoplayappend', '#CurrentPlaylistContainer tbody', '', '');
}
}
},
ontimeout: function (status) {
if (debug) { console.log('The status is ' + status.success + ', the error type is ' + status.error.type); }
}
});
if (position == 0) {
soundManager.play('audio');
soundManager.setVolume('audio', volume);
} else {
var p = position;
seekAndPlay('audio', p);
soundManager.setVolume('audio', volume);
}
if (getCookie('SaveTrackPosition')) {
if (timerid != 0) {
clearInterval(timerid);
if (!loadonly) {
$(this).jPlayer("play")
} else {
$(this).jPlayer("pause", position)
}
timerid = window.setInterval(function () {
if (getCookie('SaveTrackPosition')) {
var sm = soundManager.getSoundById('audio');
if (sm !== undefined) {
saveTrackPosition();
}
},
ended: function() { // The $.jPlayer.event.ended event
var next = $('#CurrentPlaylistContainer tr.playing').next();
if (!changeTrack(next)) {
if (getCookie('AutoPilot')) {
getRandomSongList('autoplayappend', '#CurrentPlaylistContainer tbody', '', '');
}
}, 5000);
}
var submenu = $('div#submenu_CurrentPlaylist');
if (submenu.is(":visible")) {
submenu.fadeOut();
}
}
});
if (getCookie('SaveTrackPosition')) {
if (timerid != 0) {
clearInterval(timerid);
}
timerid = window.setInterval(function () {
if (getCookie('SaveTrackPosition')) {
var audio = typeof $("#playdeck").data("jPlayer") != 'undefined' ? true : false;
if (audio) {
saveTrackPosition();
}
}
}, 5000);
}
var submenu = $('div#submenu_CurrentPlaylist');
if (submenu.is(":visible")) {
submenu.fadeOut();
}
var spechtml = '';
var data = $('#playdeck').data().jPlayer;
for (i = 0; i < data.solutions.length; i++) {
var solution = data.solutions[i];
if (data[solution].used) {
spechtml += "<strong>" + solution + "</strong> is";
spechtml += " being used with<strong>";
for (format in data[solution].support) {
if (data[solution].support[format]) {
spechtml += " " + format;
}
}
spechtml += "</strong> support";
}
}
$('#SMStats').html(spechtml);
$('table.songlist tr.song').removeClass('playing');
if (el != null) {
$(el).addClass('playing');
}
$('#PlayTrack').find('img').attr('src', 'images/pause_24x32.png');
$('#PlayTrack').addClass('playing');
scrobbleSong(false);
scrobbled = false;
@ -186,31 +158,9 @@ function playSong(el, songid, albumid, position, loadonly) {
} else {
setTitle(toHTML.un(artist) + ' - ' + toHTML.un(title));
}
}
}
});
}
function seekAndPlay(soundID, soundPosition) {
var s = soundManager.getSoundById(soundID);
if (s) {
s.unload();
if (s.readyState === 0) { // hasn't started loading yet...
// load the whole sound, and play when it's done
s.load({
onload: function () {
this.play({
position: soundPosition
});
}
});
} else if (s.readyState === 3) {
// sound has already loaded, ready to go
s.play({
position: soundPosition
});
}
}
}
function scrobbleSong(submission) {
var songid = $('#songdetails_song').attr('childid');
$.ajax({
@ -256,41 +206,13 @@ function starItem(itemid, starred) {
}
}
function playPauseSong() {
var el = '#PlayTrack';
if ($(el).hasClass('playing')) {
$(el).find('img').attr('src', 'images/play_24x32.png');
$(el).removeClass('playing');
$(el).addClass('paused');
soundManager.pause('audio');
} else if ($(el).hasClass('paused')) {
$(el).find('img').attr('src', 'images/pause_24x32.png');
$(el).removeClass('paused');
$(el).addClass('playing');
soundManager.resume('audio');
} else {
var el = $('#songdetails_song');
var songid = el.attr('childid');
if (songid != '') {
if (getCookie("CurrentSong")) {
var currentSong = JSON.parse(getCookie("CurrentSong"));
playSong($('#' + songid), currentSong.songid, currentSong.albumid, currentSong.position, false);
var playing = $('#' + songid);
if (playing != undefined) {
$('#CurrentPlaylist').scrollTo(playing, 400);
}
}
if (typeof $("#playdeck").data("jPlayer") != 'undefined') {
if ($("#playdeck").data("jPlayer").status.paused) {
$("#playdeck").jPlayer("play");
} else {
// Start playing song
var play = $('#CurrentPlaylistContainer tr.selected').first();
if (changeTrack(play)) {
$(el).find('img').attr('src', 'images/pause_24x32.png');
$(el).addClass('playing');
} else {
var first = $('#CurrentPlaylistContainer tr').first();
changeTrack(first);
}
$("#playdeck").jPlayer("pause");
}
}
}
}
function changeTrack(next) {
var songid = $(next).attr('childid');