2014-04-11 08:36:25 -07:00
|
|
|
|
(function (window, document, $, setTimeout, clearTimeout) {
|
|
|
|
|
|
|
|
|
|
var currentPlayer;
|
|
|
|
|
|
|
|
|
|
var currentTimeElement;
|
|
|
|
|
var nowPlayingImageElement;
|
|
|
|
|
var nowPlayingTextElement;
|
2015-06-13 08:52:46 -07:00
|
|
|
|
var nowPlayingUserData;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
var unmuteButton;
|
|
|
|
|
var muteButton;
|
|
|
|
|
var volumeSlider;
|
|
|
|
|
var unpauseButton;
|
|
|
|
|
var pauseButton;
|
|
|
|
|
var positionSlider;
|
|
|
|
|
|
|
|
|
|
var lastPlayerState;
|
|
|
|
|
|
|
|
|
|
function getNowPlayingBarHtml() {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2015-06-17 18:41:22 -07:00
|
|
|
|
// add return false because on iOS clicking the bar often ends up clicking the content underneath.
|
2015-06-26 20:27:38 -07:00
|
|
|
|
html += '<div class="nowPlayingBar" style="display:none;">';
|
2014-06-21 22:52:31 -07:00
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<div class="nowPlayingBarPositionContainer">';
|
|
|
|
|
html += '<paper-slider pin step=".1" min="0" max="100" value="0" class="nowPlayingBarPositionSlider"></paper-slider>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<div class="nowPlayingBarInfoContainer">';
|
2015-05-01 11:37:01 -07:00
|
|
|
|
html += '<div class="nowPlayingImage"></div>';
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<div class="nowPlayingBarText"></div>';
|
|
|
|
|
html += '</div>';
|
2015-05-01 11:37:01 -07:00
|
|
|
|
|
2015-06-17 18:41:22 -07:00
|
|
|
|
// The onclicks are needed due to the return false above
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<div class="nowPlayingBarCenter">';
|
2015-05-01 11:37:01 -07:00
|
|
|
|
|
2015-06-23 21:38:46 -07:00
|
|
|
|
html += '<paper-icon-button icon="skip-previous" class="previousTrackButton mediaButton"></paper-icon-button>';
|
2014-06-21 22:52:31 -07:00
|
|
|
|
|
2015-06-23 21:38:46 -07:00
|
|
|
|
html += '<paper-icon-button icon="play-arrow" class="mediaButton unpauseButton"></paper-icon-button>';
|
|
|
|
|
html += '<paper-icon-button icon="pause" class="mediaButton pauseButton"></paper-icon-button>';
|
2014-06-24 14:45:21 -07:00
|
|
|
|
|
2015-06-23 21:38:46 -07:00
|
|
|
|
html += '<paper-icon-button icon="stop" class="stopButton mediaButton"></paper-icon-button>';
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-23 21:38:46 -07:00
|
|
|
|
html += '<paper-icon-button icon="skip-next" class="nextTrackButton mediaButton"></paper-icon-button>';
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<div class="nowPlayingBarCurrentTime"></div>';
|
2014-04-11 08:36:25 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<div class="nowPlayingBarRight">';
|
|
|
|
|
|
2015-06-23 21:38:46 -07:00
|
|
|
|
html += '<paper-icon-button icon="volume-up" class="muteButton mediaButton"></paper-icon-button>';
|
|
|
|
|
html += '<paper-icon-button icon="volume-off" class="unmuteButton mediaButton"></paper-icon-button>';
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<paper-slider pin step="1" min="0" max="100" value="0" class="nowPlayingBarVolumeSlider" style="width:100px;vertical-align:middle;"></paper-slider>';
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-13 08:52:46 -07:00
|
|
|
|
html += '<div class="nowPlayingBarUserDataButtons">';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
html += '<paper-icon-button icon="play-arrow" class="mediaButton unpauseButton"></paper-icon-button>';
|
|
|
|
|
html += '<paper-icon-button icon="pause" class="mediaButton pauseButton"></paper-icon-button>';
|
|
|
|
|
html += '<paper-icon-button icon="tablet-android" onclick="Dashboard.navigate(\'nowplaying.html\', false);" class="mediaButton remoteControlButton"></paper-icon-button>';
|
|
|
|
|
html += '<paper-icon-button icon="queue-music" onclick="Dashboard.navigate(\'nowplaying.html?tab=Playlist\', false);" class="mediaButton playlistButton"></paper-icon-button>';
|
|
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bindEvents(elem) {
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
currentTimeElement = $('.nowPlayingBarCurrentTime', elem);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
nowPlayingImageElement = $('.nowPlayingImage', elem);
|
2015-06-27 12:53:36 -07:00
|
|
|
|
nowPlayingTextElement = $('.nowPlayingBarText', elem);
|
2015-06-13 08:52:46 -07:00
|
|
|
|
nowPlayingUserData = $('.nowPlayingBarUserDataButtons', elem);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-03-17 21:09:31 -07:00
|
|
|
|
$(elem).on('swipeup', function () {
|
|
|
|
|
Dashboard.navigate('nowplaying.html');
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
unmuteButton = $('.unmuteButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.unMute();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
muteButton = $('.muteButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.mute();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.stopButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.stop();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
pauseButton = $('.pauseButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.pause();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
unpauseButton = $('.unpauseButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.unpause();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.nextTrackButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.nextTrack();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.previousTrackButton', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.previousTrack();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
volumeSlider = $('.nowPlayingBarVolumeSlider', elem).on('change', function () {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.setVolume(this.value);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
})[0];
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
positionSlider = $('.nowPlayingBarPositionSlider', elem).on('change', function () {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
if (currentPlayer && lastPlayerState) {
|
|
|
|
|
|
2014-04-11 20:48:57 -07:00
|
|
|
|
var newPercent = parseFloat(this.value);
|
2014-04-22 10:25:54 -07:00
|
|
|
|
var newPositionTicks = (newPercent / 100) * lastPlayerState.NowPlayingItem.RunTimeTicks;
|
|
|
|
|
|
2014-04-11 20:48:57 -07:00
|
|
|
|
currentPlayer.seek(Math.floor(newPositionTicks));
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
2015-06-27 12:53:36 -07:00
|
|
|
|
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
positionSlider._setPinValue = function (value) {
|
|
|
|
|
|
|
|
|
|
var state = lastPlayerState;
|
|
|
|
|
|
|
|
|
|
if (!state || !state.NowPlayingItem || !state.NowPlayingItem.RunTimeTicks) {
|
|
|
|
|
this.pinValue = '--:--';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ticks = state.NowPlayingItem.RunTimeTicks;
|
|
|
|
|
ticks /= 100;
|
|
|
|
|
ticks *= value;
|
|
|
|
|
|
|
|
|
|
this.pinValue = Dashboard.getDisplayTime(ticks);
|
|
|
|
|
};
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getNowPlayingBar() {
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
var elem = document.querySelector('.nowPlayingBar');
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
if (elem) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
elem = $(getNowPlayingBarHtml()).insertBefore('#footerNotifications')[0];
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-29 18:56:25 -07:00
|
|
|
|
if (($.browser.safari || !AppInfo.isNativeApp) && $.browser.mobile) {
|
2015-06-27 16:18:09 -07:00
|
|
|
|
// Not handled well here. The wrong elements receive events, bar doesn't update quickly enough, etc.
|
2015-06-28 07:45:21 -07:00
|
|
|
|
elem.classList.add('noMediaProgress');
|
2015-06-27 16:18:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
bindEvents(elem);
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
2015-03-17 21:09:31 -07:00
|
|
|
|
|
2014-04-19 10:43:12 -07:00
|
|
|
|
function showButton(button) {
|
|
|
|
|
button.removeClass('hide');
|
|
|
|
|
}
|
2015-03-17 21:09:31 -07:00
|
|
|
|
|
2014-04-19 10:43:12 -07:00
|
|
|
|
function hideButton(button) {
|
|
|
|
|
button.addClass('hide');
|
|
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
function updatePlayerState(state) {
|
|
|
|
|
|
2015-06-27 16:18:09 -07:00
|
|
|
|
if (state.NowPlayingItem) {
|
2014-04-12 10:27:53 -07:00
|
|
|
|
showNowPlayingBar();
|
|
|
|
|
} else {
|
|
|
|
|
hideNowPlayingBar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
lastPlayerState = state;
|
|
|
|
|
|
|
|
|
|
if (!muteButton) {
|
|
|
|
|
getNowPlayingBar();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 20:54:52 -07:00
|
|
|
|
var playerInfo = MediaController.getPlayerInfo();
|
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
var playState = state.PlayState || {};
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
if (playState.IsPaused) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-19 10:43:12 -07:00
|
|
|
|
hideButton(pauseButton);
|
|
|
|
|
showButton(unpauseButton);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2014-04-19 10:43:12 -07:00
|
|
|
|
showButton(pauseButton);
|
|
|
|
|
hideButton(unpauseButton);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
updatePlayerVolumeState(state, playerInfo);
|
2014-04-14 20:54:52 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
var nowPlayingItem = state.NowPlayingItem || {};
|
2015-06-27 12:53:36 -07:00
|
|
|
|
if (!positionSlider.dragging) {
|
2014-04-18 12:59:06 -07:00
|
|
|
|
|
2014-04-30 08:07:02 -07:00
|
|
|
|
if (nowPlayingItem && nowPlayingItem.RunTimeTicks) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
var pct = playState.PositionTicks / nowPlayingItem.RunTimeTicks;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
pct *= 100;
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
positionSlider.value = pct;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
positionSlider.value = 0;
|
2014-04-30 08:07:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
positionSlider.disabled = !playState.CanSeek;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
var timeText = Dashboard.getDisplayTime(playState.PositionTicks);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
if (nowPlayingItem.RunTimeTicks) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
timeText += " / " + Dashboard.getDisplayTime(nowPlayingItem.RunTimeTicks);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentTimeElement.html(timeText);
|
2014-04-12 10:27:53 -07:00
|
|
|
|
|
|
|
|
|
updateNowPlayingInfo(state);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
function updatePlayerVolumeState(state, playerInfo) {
|
|
|
|
|
|
|
|
|
|
playerInfo = playerInfo || MediaController.getPlayerInfo();
|
2015-01-03 12:38:22 -07:00
|
|
|
|
|
|
|
|
|
if (!muteButton) {
|
|
|
|
|
getNowPlayingBar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var playState = state.PlayState || {};
|
2015-05-21 13:53:14 -07:00
|
|
|
|
var supportedCommands = playerInfo.supportedCommands;
|
2015-01-03 12:38:22 -07:00
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
var showMuteButton = true;
|
|
|
|
|
var showUnmuteButton = true;
|
|
|
|
|
var showVolumeSlider = true;
|
2015-01-03 12:38:22 -07:00
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
if (supportedCommands.indexOf('Mute') == -1) {
|
|
|
|
|
showMuteButton = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (supportedCommands.indexOf('Unmute') == -1) {
|
|
|
|
|
showUnmuteButton = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playState.IsMuted) {
|
2015-01-03 12:38:22 -07:00
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
showMuteButton = false;
|
2015-01-03 12:38:22 -07:00
|
|
|
|
} else {
|
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
showUnmuteButton = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (supportedCommands.indexOf('SetVolume') == -1) {
|
|
|
|
|
showVolumeSlider = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playerInfo.isLocalPlayer && AppInfo.hasPhysicalVolumeButtons) {
|
|
|
|
|
showMuteButton = false;
|
|
|
|
|
showUnmuteButton = false;
|
|
|
|
|
showVolumeSlider = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showMuteButton) {
|
2015-01-03 12:38:22 -07:00
|
|
|
|
showButton(muteButton);
|
2015-05-21 13:53:14 -07:00
|
|
|
|
} else {
|
|
|
|
|
hideButton(muteButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (showUnmuteButton) {
|
|
|
|
|
showButton(unmuteButton);
|
|
|
|
|
} else {
|
2015-01-03 12:38:22 -07:00
|
|
|
|
hideButton(unmuteButton);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
$(volumeSlider).visible(showVolumeSlider);
|
2015-05-21 13:53:14 -07:00
|
|
|
|
|
2015-06-27 12:53:36 -07:00
|
|
|
|
if (!volumeSlider.dragging) {
|
|
|
|
|
volumeSlider.value = playState.VolumeLevel || 0;
|
2015-01-03 12:38:22 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 10:27:13 -07:00
|
|
|
|
var currentImgUrl;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
function updateNowPlayingInfo(state) {
|
|
|
|
|
|
2015-05-08 20:48:43 -07:00
|
|
|
|
var nameHtml = MediaController.getNowPlayingNameHtml(state.NowPlayingItem) || '';
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-13 10:27:13 -07:00
|
|
|
|
if (nameHtml.indexOf('<br/>') != -1) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
nowPlayingTextElement.addClass('nowPlayingDoubleText');
|
|
|
|
|
} else {
|
|
|
|
|
nowPlayingTextElement.removeClass('nowPlayingDoubleText');
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 20:27:38 -07:00
|
|
|
|
if (state.NowPlayingItem.Id) {
|
|
|
|
|
nameHtml = '<a style="color:inherit;text-decoration:none;" href="' + LibraryBrowser.getHref(state.NowPlayingItem) + '">' + nameHtml + '</a>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 10:27:13 -07:00
|
|
|
|
nowPlayingTextElement.html(nameHtml);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
var url;
|
2015-06-27 12:53:36 -07:00
|
|
|
|
var imgHeight = 90;
|
2015-03-17 21:09:31 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
var nowPlayingItem = state.NowPlayingItem;
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
if (nowPlayingItem.PrimaryImageTag) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-05-23 16:58:28 -07:00
|
|
|
|
url = ApiClient.getScaledImageUrl(nowPlayingItem.PrimaryImageItemId, {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
type: "Primary",
|
2015-05-01 11:37:01 -07:00
|
|
|
|
height: imgHeight,
|
2014-04-22 10:25:54 -07:00
|
|
|
|
tag: nowPlayingItem.PrimaryImageTag
|
2014-04-11 08:36:25 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-04-22 10:25:54 -07:00
|
|
|
|
else if (nowPlayingItem.BackdropImageTag) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-05-23 16:58:28 -07:00
|
|
|
|
url = ApiClient.getScaledImageUrl(nowPlayingItem.BackdropItemId, {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
type: "Backdrop",
|
2015-05-01 11:37:01 -07:00
|
|
|
|
height: imgHeight,
|
2014-04-22 10:25:54 -07:00
|
|
|
|
tag: nowPlayingItem.BackdropImageTag,
|
2014-04-11 08:36:25 -07:00
|
|
|
|
index: 0
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
} else if (nowPlayingItem.ThumbImageTag) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-05-23 16:58:28 -07:00
|
|
|
|
url = ApiClient.getScaledImageUrl(nowPlayingItem.ThumbImageItemId, {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
type: "Thumb",
|
2015-05-01 11:37:01 -07:00
|
|
|
|
height: imgHeight,
|
2014-04-22 10:25:54 -07:00
|
|
|
|
tag: nowPlayingItem.ThumbImageTag
|
2014-04-11 08:36:25 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
else if (nowPlayingItem.Type == "TvChannel" || nowPlayingItem.Type == "Recording") {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
url = "css/images/items/detail/tv.png";
|
|
|
|
|
}
|
2014-04-22 10:25:54 -07:00
|
|
|
|
else if (nowPlayingItem.MediaType == "Audio") {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
url = "css/images/items/detail/audio.png";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
url = "css/images/items/detail/video.png";
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 10:27:13 -07:00
|
|
|
|
if (url == currentImgUrl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentImgUrl = url;
|
2015-03-17 21:09:31 -07:00
|
|
|
|
|
2015-06-26 20:27:38 -07:00
|
|
|
|
var imgHtml = '<img src="' + url + '" />';
|
|
|
|
|
|
|
|
|
|
nowPlayingImageElement.html(imgHtml);
|
2015-06-13 08:52:46 -07:00
|
|
|
|
|
|
|
|
|
if (nowPlayingItem.Id) {
|
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), nowPlayingItem.Id).done(function (item) {
|
2015-06-14 10:55:42 -07:00
|
|
|
|
nowPlayingUserData.html(LibraryBrowser.getUserDataIconsHtml(item, false));
|
2015-06-13 08:52:46 -07:00
|
|
|
|
});
|
2015-06-27 16:18:09 -07:00
|
|
|
|
} else {
|
|
|
|
|
nowPlayingUserData.html('');
|
2015-06-13 08:52:46 -07:00
|
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlaybackStart(e, state) {
|
|
|
|
|
|
2015-06-26 20:27:38 -07:00
|
|
|
|
Logger.log('nowplaying event: ' + e.type);
|
2014-04-19 10:43:12 -07:00
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
var player = this;
|
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
|
player.beginPlayerUpdates();
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
|
onStateChanged.call(player, e, state);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showNowPlayingBar() {
|
|
|
|
|
|
|
|
|
|
var nowPlayingBar = getNowPlayingBar();
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
$(nowPlayingBar).show();
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideNowPlayingBar() {
|
|
|
|
|
|
|
|
|
|
// Use a timeout to prevent the bar from hiding and showing quickly
|
|
|
|
|
// in the event of a stop->play command
|
2015-06-13 08:52:46 -07:00
|
|
|
|
|
|
|
|
|
// Don't call getNowPlayingBar here because we don't want to end up creating it just to hide it
|
2015-06-28 07:45:21 -07:00
|
|
|
|
var elem = document.getElementsByClassName('nowPlayingBar')[0];
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.style.display = 'none';
|
|
|
|
|
}
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlaybackStopped(e, state) {
|
|
|
|
|
|
2015-06-26 20:27:38 -07:00
|
|
|
|
Logger.log('nowplaying event: ' + e.type);
|
2014-04-12 10:27:53 -07:00
|
|
|
|
var player = this;
|
|
|
|
|
|
|
|
|
|
player.endPlayerUpdates();
|
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
hideNowPlayingBar();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
|
function onStateChanged(e, state) {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-26 20:27:38 -07:00
|
|
|
|
//Logger.log('nowplaying event: ' + e.type);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
var player = this;
|
|
|
|
|
|
2014-04-22 10:25:54 -07:00
|
|
|
|
if (player.isDefaultPlayer && state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePlayerState(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function releaseCurrentPlayer() {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
|
2015-06-29 11:45:42 -07:00
|
|
|
|
$(currentPlayer).off('playbackstart', onPlaybackStart)
|
|
|
|
|
.off('playbackstop', onPlaybackStopped)
|
|
|
|
|
.off('volumechange', onVolumeChanged)
|
|
|
|
|
.off('playstatechange', onStateChanged)
|
|
|
|
|
.off('positionchange', onStateChanged);
|
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
|
currentPlayer.endPlayerUpdates();
|
2014-04-11 08:36:25 -07:00
|
|
|
|
currentPlayer = null;
|
2014-04-12 10:27:53 -07:00
|
|
|
|
|
|
|
|
|
hideNowPlayingBar();
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-03 12:38:22 -07:00
|
|
|
|
function onVolumeChanged(e) {
|
|
|
|
|
|
|
|
|
|
var player = this;
|
|
|
|
|
|
2015-03-17 21:09:31 -07:00
|
|
|
|
player.getPlayerState().done(function (state) {
|
|
|
|
|
|
2015-01-03 12:38:22 -07:00
|
|
|
|
if (player.isDefaultPlayer && state.NowPlayingItem && state.NowPlayingItem.MediaType == 'Video') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePlayerVolumeState(state);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 08:36:25 -07:00
|
|
|
|
function bindToPlayer(player) {
|
|
|
|
|
|
|
|
|
|
releaseCurrentPlayer();
|
|
|
|
|
|
|
|
|
|
currentPlayer = player;
|
|
|
|
|
|
2014-04-12 10:27:53 -07:00
|
|
|
|
player.getPlayerState().done(function (state) {
|
|
|
|
|
|
2014-04-28 20:56:20 -07:00
|
|
|
|
if (state.NowPlayingItem) {
|
2014-04-12 10:27:53 -07:00
|
|
|
|
player.beginPlayerUpdates();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 21:09:31 -07:00
|
|
|
|
onStateChanged.call(player, { type: 'init' }, state);
|
2014-04-12 10:27:53 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-06-29 11:45:42 -07:00
|
|
|
|
$(player).on('playbackstart', onPlaybackStart)
|
|
|
|
|
.on('playbackstop', onPlaybackStopped)
|
|
|
|
|
.on('volumechange', onVolumeChanged)
|
|
|
|
|
.on('playstatechange', onStateChanged)
|
|
|
|
|
.on('positionchange', onStateChanged);
|
2014-04-11 08:36:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 12:15:40 -07:00
|
|
|
|
Dashboard.ready(function () {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
Events.on(MediaController, 'playerchange', function () {
|
2014-04-11 08:36:25 -07:00
|
|
|
|
|
|
|
|
|
bindToPlayer(MediaController.getCurrentPlayer());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bindToPlayer(MediaController.getCurrentPlayer());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(window, document, jQuery, setTimeout, clearTimeout);
|