2016-08-01 11:16:07 -07:00
|
|
|
|
define(['browser', 'datetime', 'libraryBrowser', 'listView', 'userdataButtons', 'cardStyle'], function (browser, datetime, libraryBrowser, listView, userdataButtons) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
function showSlideshowMenu(context) {
|
|
|
|
|
require(['scripts/slideshow'], function () {
|
|
|
|
|
SlideShow.showMenu();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showAudioMenu(context, player, button, item, currentIndex) {
|
|
|
|
|
|
|
|
|
|
var streams = (item.MediaStreams || []).filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.Type == 'Audio';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var menuItems = streams.map(function (s) {
|
|
|
|
|
|
|
|
|
|
var name = (s.Codec || '').toUpperCase();
|
|
|
|
|
|
|
|
|
|
if (s.Profile) {
|
|
|
|
|
name += ' ' + s.Profile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s.Language) {
|
|
|
|
|
name += ' · ' + s.Language;
|
|
|
|
|
}
|
|
|
|
|
if (s.Layout) {
|
|
|
|
|
name += ' · ' + s.Layout;
|
|
|
|
|
}
|
|
|
|
|
else if (s.Channels) {
|
|
|
|
|
name += ' · ' + s.Channels + ' ch';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var menuItem = {
|
2016-05-15 09:30:32 -07:00
|
|
|
|
name: s.DisplayTitle || name,
|
2016-02-05 19:47:06 -07:00
|
|
|
|
id: s.Index
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (s.Index == currentIndex) {
|
2016-05-15 09:30:32 -07:00
|
|
|
|
menuItem.selected = true;
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
require(['actionsheet'], function (actionsheet) {
|
|
|
|
|
|
|
|
|
|
actionsheet.show({
|
|
|
|
|
items: menuItems,
|
|
|
|
|
positionTo: button,
|
|
|
|
|
callback: function (id) {
|
|
|
|
|
|
|
|
|
|
player.setAudioStreamIndex(parseInt(id));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSubtitleMenu(context, player, button, item, currentIndex) {
|
|
|
|
|
|
|
|
|
|
var streams = (item.MediaStreams || []).filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.Type == 'Subtitle';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var menuItems = streams.map(function (s) {
|
|
|
|
|
|
|
|
|
|
var name = (s.Language || Globalize.translate('LabelUnknownLanguage'));
|
|
|
|
|
|
|
|
|
|
if (s.IsDefault && s.IsForced) {
|
|
|
|
|
name += ' · ' + Globalize.translate('LabelDefaultForcedStream');
|
|
|
|
|
}
|
|
|
|
|
else if (s.IsDefault) {
|
|
|
|
|
name += ' · ' + Globalize.translate('LabelDefaultStream');
|
|
|
|
|
}
|
|
|
|
|
else if (s.IsForced) {
|
|
|
|
|
name += ' · ' + Globalize.translate('LabelForcedStream');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s.Codec) {
|
|
|
|
|
name += ' · ' + s.Codec.toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var menuItem = {
|
2016-05-15 09:30:32 -07:00
|
|
|
|
name: s.DisplayTitle || name,
|
2016-02-05 19:47:06 -07:00
|
|
|
|
id: s.Index
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (s.Index == currentIndex) {
|
2016-05-15 09:30:32 -07:00
|
|
|
|
menuItem.selected = true;
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
menuItems.unshift({
|
|
|
|
|
id: -1,
|
|
|
|
|
name: Globalize.translate('ButtonOff'),
|
2016-06-18 22:26:52 -07:00
|
|
|
|
selected: currentIndex == null
|
2016-02-05 19:47:06 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
require(['actionsheet'], function (actionsheet) {
|
|
|
|
|
|
|
|
|
|
actionsheet.show({
|
|
|
|
|
items: menuItems,
|
|
|
|
|
positionTo: button,
|
|
|
|
|
callback: function (id) {
|
|
|
|
|
|
|
|
|
|
player.setSubtitleStreamIndex(parseInt(id));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showButton(button) {
|
|
|
|
|
button.classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideButton(button) {
|
|
|
|
|
button.classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasStreams(item, type) {
|
|
|
|
|
return item && item.MediaStreams && item.MediaStreams.filter(function (i) {
|
|
|
|
|
return i.Type == type;
|
|
|
|
|
}).length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentImgUrl;
|
|
|
|
|
function updateNowPlayingInfo(context, state) {
|
|
|
|
|
|
|
|
|
|
var item = state.NowPlayingItem;
|
|
|
|
|
var displayName = item ? MediaController.getNowPlayingNameHtml(item).replace('<br/>', ' - ') : '';
|
|
|
|
|
|
|
|
|
|
context.querySelector('.nowPlayingPageTitle').innerHTML = displayName;
|
|
|
|
|
|
|
|
|
|
if (displayName.length > 0) {
|
|
|
|
|
context.querySelector('.nowPlayingPageTitle').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.nowPlayingPageTitle').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var url;
|
|
|
|
|
var backdropUrl = null;
|
|
|
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
|
}
|
|
|
|
|
else if (item.PrimaryImageTag) {
|
|
|
|
|
|
|
|
|
|
url = ApiClient.getScaledImageUrl(item.PrimaryImageItemId, {
|
|
|
|
|
type: "Primary",
|
|
|
|
|
maxHeight: 300,
|
|
|
|
|
tag: item.PrimaryImageTag
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (item.BackdropImageTag) {
|
|
|
|
|
|
|
|
|
|
url = ApiClient.getScaledImageUrl(item.BackdropItemId, {
|
|
|
|
|
type: "Backdrop",
|
|
|
|
|
maxHeight: 300,
|
|
|
|
|
tag: item.BackdropImageTag,
|
|
|
|
|
index: 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else if (item.ThumbImageTag) {
|
|
|
|
|
|
|
|
|
|
url = ApiClient.getScaledImageUrl(item.ThumbImageItemId, {
|
|
|
|
|
type: "Thumb",
|
|
|
|
|
maxHeight: 300,
|
|
|
|
|
tag: item.ThumbImageTag
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (url == currentImgUrl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item && item.BackdropImageTag) {
|
|
|
|
|
|
|
|
|
|
backdropUrl = ApiClient.getScaledImageUrl(item.BackdropItemId, {
|
|
|
|
|
type: "Backdrop",
|
|
|
|
|
maxHeight: 300,
|
|
|
|
|
tag: item.BackdropImageTag,
|
|
|
|
|
index: 0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setImageUrl(context, url);
|
|
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
|
|
|
|
|
|
// This should be outside of the IF
|
|
|
|
|
// But for now, if you change songs but keep the same artist, the backdrop will flicker because in-between songs it clears out the image
|
2016-08-06 07:07:44 -07:00
|
|
|
|
if (!browser.slow) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
// Exclude from mobile because it just doesn't perform well
|
2016-03-12 00:28:13 -07:00
|
|
|
|
require(['backdrop'], function (backdrop) {
|
|
|
|
|
backdrop.setBackdrop(backdropUrl);
|
|
|
|
|
});
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), item.Id).then(function (fullItem) {
|
2016-07-17 23:45:29 -07:00
|
|
|
|
context.querySelector('.nowPlayingPageUserDataButtons').innerHTML = userdataButtons.getIconsHtml({
|
|
|
|
|
item: fullItem,
|
|
|
|
|
includePlayed: false,
|
|
|
|
|
style: 'fab-mini'
|
|
|
|
|
});
|
2016-02-05 19:47:06 -07:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.nowPlayingPageUserDataButtons').innerHTML = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setImageUrl(context, url) {
|
|
|
|
|
currentImgUrl = url;
|
|
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
|
ImageLoader.lazyImage(context.querySelector('.nowPlayingPageImage'), url);
|
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.nowPlayingPageImage').style.backgroundImage = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buttonEnabled(btn, enabled) {
|
|
|
|
|
btn.disabled = !enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateSupportedCommands(context, commands) {
|
|
|
|
|
|
|
|
|
|
var all = context.querySelectorAll('.btnCommand');
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = all.length; i < length; i++) {
|
|
|
|
|
buttonEnabled(all[i], commands.indexOf(all[i].getAttribute('data-command')) != -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideChapterMenu(page) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return function () {
|
|
|
|
|
|
|
|
|
|
var dlg;
|
|
|
|
|
var currentPlayer;
|
|
|
|
|
var lastPlayerState;
|
|
|
|
|
var lastUpdateTime = 0;
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
var playlistNeedsRefresh = true;
|
|
|
|
|
|
|
|
|
|
function toggleRepeat(player) {
|
|
|
|
|
|
|
|
|
|
if (player && lastPlayerState) {
|
|
|
|
|
var state = lastPlayerState;
|
|
|
|
|
switch ((state.PlayState || {}).RepeatMode) {
|
|
|
|
|
case 'RepeatNone':
|
|
|
|
|
player.setRepeatMode('RepeatAll');
|
|
|
|
|
break;
|
|
|
|
|
case 'RepeatAll':
|
|
|
|
|
player.setRepeatMode('RepeatOne');
|
|
|
|
|
break;
|
|
|
|
|
case 'RepeatOne':
|
|
|
|
|
player.setRepeatMode('RepeatNone');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updatePlayerState(context, state) {
|
|
|
|
|
|
|
|
|
|
lastPlayerState = state;
|
|
|
|
|
|
|
|
|
|
var item = state.NowPlayingItem;
|
|
|
|
|
|
|
|
|
|
var playerInfo = MediaController.getPlayerInfo();
|
|
|
|
|
|
|
|
|
|
var supportedCommands = playerInfo.supportedCommands;
|
|
|
|
|
var playState = state.PlayState || {};
|
|
|
|
|
|
|
|
|
|
buttonEnabled(context.querySelector('.btnToggleFullscreen'), item && item.MediaType == 'Video' && supportedCommands.indexOf('ToggleFullscreen') != -1);
|
|
|
|
|
buttonEnabled(context.querySelector('.btnAudioTracks'), hasStreams(item, 'Audio') && supportedCommands.indexOf('SetAudioStreamIndex') != -1);
|
|
|
|
|
buttonEnabled(context.querySelector('.btnSubtitles'), hasStreams(item, 'Subtitle') && supportedCommands.indexOf('SetSubtitleStreamIndex') != -1);
|
|
|
|
|
|
|
|
|
|
if (item && item.Chapters && item.Chapters.length && playState.CanSeek) {
|
|
|
|
|
buttonEnabled(context.querySelector('.btnChapters'), true);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
buttonEnabled(context.querySelector('.btnChapters'), false);
|
|
|
|
|
hideChapterMenu(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (supportedCommands.indexOf('DisplayMessage') != -1) {
|
|
|
|
|
context.querySelector('.sendMessageSection').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.sendMessageSection').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
if (supportedCommands.indexOf('SendString') != -1) {
|
|
|
|
|
context.querySelector('.sendTextSection').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.sendTextSection').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttonEnabled(context.querySelector('.btnStop'), item != null);
|
|
|
|
|
buttonEnabled(context.querySelector('.btnNextTrack'), item != null);
|
|
|
|
|
buttonEnabled(context.querySelector('.btnPreviousTrack'), item != null);
|
|
|
|
|
|
|
|
|
|
var btnPause = context.querySelector('.btnPause');
|
|
|
|
|
var btnPlay = context.querySelector('.btnPlay');
|
|
|
|
|
|
|
|
|
|
buttonEnabled(btnPause, item != null);
|
|
|
|
|
buttonEnabled(btnPlay, item != null);
|
|
|
|
|
|
|
|
|
|
if (playState.IsPaused) {
|
|
|
|
|
|
|
|
|
|
hideButton(btnPause);
|
|
|
|
|
showButton(btnPlay);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
showButton(btnPause);
|
|
|
|
|
hideButton(btnPlay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var positionSlider = context.querySelector('.nowPlayingPositionSlider');
|
|
|
|
|
|
|
|
|
|
if (!positionSlider.dragging) {
|
|
|
|
|
|
|
|
|
|
if (item && item.RunTimeTicks) {
|
|
|
|
|
|
|
|
|
|
var pct = playState.PositionTicks / item.RunTimeTicks;
|
|
|
|
|
pct *= 100;
|
|
|
|
|
|
|
|
|
|
positionSlider.value = pct;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
positionSlider.value = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
positionSlider.disabled = !playState.CanSeek;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playState.PositionTicks == null) {
|
|
|
|
|
context.querySelector('.positionTime').innerHTML = '--:--';
|
|
|
|
|
} else {
|
2016-05-05 20:09:36 -07:00
|
|
|
|
context.querySelector('.positionTime').innerHTML = datetime.getDisplayRunningTime(playState.PositionTicks);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item && item.RunTimeTicks != null) {
|
2016-05-05 20:09:36 -07:00
|
|
|
|
context.querySelector('.runtime').innerHTML = datetime.getDisplayRunningTime(item.RunTimeTicks);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.runtime').innerHTML = '--:--';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item && item.MediaType == 'Video') {
|
|
|
|
|
context.classList.remove('hideVideoButtons');
|
|
|
|
|
} else {
|
|
|
|
|
context.classList.add('hideVideoButtons');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playerInfo.isLocalPlayer && AppInfo.hasPhysicalVolumeButtons) {
|
|
|
|
|
context.classList.add('hideVolumeButtons');
|
|
|
|
|
} else {
|
|
|
|
|
context.classList.remove('hideVolumeButtons');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item && item.MediaType == 'Audio') {
|
|
|
|
|
context.querySelector('.buttonsRow2').classList.add('hide');
|
|
|
|
|
} else {
|
|
|
|
|
context.querySelector('.buttonsRow2').classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var toggleRepeatButton = context.querySelector('.repeatToggleButton');
|
|
|
|
|
|
|
|
|
|
if (playState.RepeatMode == 'RepeatAll') {
|
2016-06-18 13:31:22 -07:00
|
|
|
|
toggleRepeatButton.innerHTML = "<i class='md-icon'>repeat</i>";
|
2016-02-05 19:47:06 -07:00
|
|
|
|
toggleRepeatButton.classList.add('nowPlayingPageRepeatActive');
|
|
|
|
|
}
|
|
|
|
|
else if (playState.RepeatMode == 'RepeatOne') {
|
2016-06-18 13:31:22 -07:00
|
|
|
|
toggleRepeatButton.innerHTML = "<i class='md-icon'>repeat_one</i>";
|
2016-02-05 19:47:06 -07:00
|
|
|
|
toggleRepeatButton.classList.add('nowPlayingPageRepeatActive');
|
|
|
|
|
} else {
|
2016-06-18 13:31:22 -07:00
|
|
|
|
toggleRepeatButton.innerHTML = "<i class='md-icon'>repeat</i>";
|
2016-02-05 19:47:06 -07:00
|
|
|
|
toggleRepeatButton.classList.remove('nowPlayingPageRepeatActive');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateNowPlayingInfo(context, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadPlaylist(context) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
//ApiClient.getItems(Dashboard.getCurrentUserId(), {
|
|
|
|
|
|
|
|
|
|
// SortBy: "SortName",
|
|
|
|
|
// SortOrder: "Ascending",
|
|
|
|
|
// IncludeItemTypes: "Audio",
|
|
|
|
|
// Recursive: true,
|
2016-08-01 22:55:52 -07:00
|
|
|
|
// Fields: "PrimaryImageAspectRatio,SortName,MediaSourceCount",
|
2016-02-05 19:47:06 -07:00
|
|
|
|
// StartIndex: 0,
|
|
|
|
|
// ImageTypeLimit: 1,
|
|
|
|
|
// EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
// Limit: 100
|
|
|
|
|
|
|
|
|
|
//}).then(function (result) {
|
|
|
|
|
|
2016-07-15 22:05:40 -07:00
|
|
|
|
// html += listView.getListViewHtml({
|
2016-02-05 19:47:06 -07:00
|
|
|
|
// items: result.Items,
|
|
|
|
|
// smallIcon: true
|
|
|
|
|
// });
|
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
// page(".playlist").html(html).lazyChildren();
|
2016-02-05 19:47:06 -07:00
|
|
|
|
//});
|
|
|
|
|
|
2016-07-15 22:05:40 -07:00
|
|
|
|
html += listView.getListViewHtml({
|
2016-05-19 12:57:30 -07:00
|
|
|
|
items: MediaController.playlist(),
|
2016-07-16 11:02:39 -07:00
|
|
|
|
smallIcon: true,
|
2016-07-16 14:28:15 -07:00
|
|
|
|
action: 'setplaylistindex'
|
2016-05-19 12:57:30 -07:00
|
|
|
|
});
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
playlistNeedsRefresh = false;
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
var deps = [];
|
|
|
|
|
|
|
|
|
|
require(deps, function () {
|
|
|
|
|
|
|
|
|
|
var itemsContainer = context.querySelector('.playlist');
|
|
|
|
|
|
|
|
|
|
itemsContainer.innerHTML = html;
|
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
var index = MediaController.currentPlaylistIndex();
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
if (index != -1) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
var item = itemsContainer.querySelectorAll('.listItem')[index];
|
|
|
|
|
if (item) {
|
2016-06-26 21:19:10 -07:00
|
|
|
|
var img = item.querySelector('.listItemImage');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
img.classList.remove('lazy');
|
|
|
|
|
img.classList.add('playlistIndexIndicatorImage');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageLoader.lazyChildren(itemsContainer);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onStateChanged(e, state) {
|
|
|
|
|
|
|
|
|
|
if (e.type == 'positionchange') {
|
|
|
|
|
// Try to avoid hammering the document with changes
|
|
|
|
|
var now = new Date().getTime();
|
|
|
|
|
if ((now - lastUpdateTime) < 700) {
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lastUpdateTime = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePlayerState(dlg, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlaybackStart(e, state) {
|
|
|
|
|
|
|
|
|
|
var player = this;
|
|
|
|
|
|
|
|
|
|
player.beginPlayerUpdates();
|
|
|
|
|
|
|
|
|
|
onStateChanged.call(player, e, state);
|
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
loadPlaylist(dlg);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlaybackStopped(e, state) {
|
|
|
|
|
|
|
|
|
|
var player = this;
|
|
|
|
|
|
|
|
|
|
player.endPlayerUpdates();
|
|
|
|
|
|
|
|
|
|
onStateChanged.call(player, e, {});
|
|
|
|
|
|
2016-05-19 12:57:30 -07:00
|
|
|
|
loadPlaylist(dlg);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function releaseCurrentPlayer() {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
|
|
|
|
|
Events.off(currentPlayer, 'playbackstart', onPlaybackStart);
|
|
|
|
|
Events.off(currentPlayer, 'playbackstop', onPlaybackStopped);
|
|
|
|
|
Events.off(currentPlayer, 'volumechange', onStateChanged);
|
|
|
|
|
Events.off(currentPlayer, 'playstatechange', onStateChanged);
|
|
|
|
|
Events.off(currentPlayer, 'positionchange', onStateChanged);
|
|
|
|
|
|
|
|
|
|
currentPlayer.endPlayerUpdates();
|
|
|
|
|
currentPlayer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bindToPlayer(context, player) {
|
|
|
|
|
|
|
|
|
|
releaseCurrentPlayer();
|
|
|
|
|
|
|
|
|
|
currentPlayer = player;
|
|
|
|
|
|
|
|
|
|
player.getPlayerState().then(function (state) {
|
|
|
|
|
|
|
|
|
|
if (state.NowPlayingItem) {
|
|
|
|
|
player.beginPlayerUpdates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onStateChanged.call(player, { type: 'init' }, state);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Events.on(player, 'playbackstart', onPlaybackStart);
|
|
|
|
|
Events.on(player, 'playbackstop', onPlaybackStopped);
|
|
|
|
|
Events.on(player, 'volumechange', onStateChanged);
|
|
|
|
|
Events.on(player, 'playstatechange', onStateChanged);
|
|
|
|
|
Events.on(player, 'positionchange', onStateChanged);
|
|
|
|
|
|
|
|
|
|
var playerInfo = MediaController.getPlayerInfo();
|
|
|
|
|
|
|
|
|
|
var supportedCommands = playerInfo.supportedCommands;
|
|
|
|
|
|
|
|
|
|
updateSupportedCommands(context, supportedCommands);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateCastIcon(context) {
|
|
|
|
|
|
|
|
|
|
var info = MediaController.getPlayerInfo();
|
2016-02-09 11:05:12 -07:00
|
|
|
|
var btnCast = context.querySelector('.nowPlayingCastIcon');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
if (info.isLocalPlayer) {
|
|
|
|
|
|
2016-06-18 13:31:22 -07:00
|
|
|
|
btnCast.querySelector('i').innerHTML = 'cast';
|
2016-02-09 11:05:12 -07:00
|
|
|
|
btnCast.classList.remove('btnActiveCast');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
context.querySelector('.nowPlayingSelectedPlayer').innerHTML = '';
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2016-08-08 22:10:17 -07:00
|
|
|
|
btnCast.querySelector('i').innerHTML = 'cast_connected';
|
2016-02-09 11:05:12 -07:00
|
|
|
|
btnCast.classList.add('btnActiveCast');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
context.querySelector('.nowPlayingSelectedPlayer').innerHTML = info.deviceName || info.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parentWithClass(elem, className) {
|
|
|
|
|
|
|
|
|
|
while (!elem.classList || !elem.classList.contains(className)) {
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
function onBtnCommandClick() {
|
|
|
|
|
if (currentPlayer) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
if (this.classList.contains('repeatToggleButton')) {
|
|
|
|
|
toggleRepeat(currentPlayer);
|
|
|
|
|
} else {
|
|
|
|
|
MediaController.sendCommand({
|
|
|
|
|
Name: this.getAttribute('data-command')
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
}, currentPlayer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
function bindEvents(context) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
var btnCommand = context.querySelectorAll('.btnCommand');
|
|
|
|
|
for (var i = 0, length = btnCommand.length; i < length; i++) {
|
|
|
|
|
btnCommand[i].addEventListener('click', onBtnCommandClick);
|
|
|
|
|
}
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
context.querySelector('.btnToggleFullscreen').addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
MediaController.sendCommand({
|
|
|
|
|
Name: e.target.getAttribute('data-command')
|
|
|
|
|
|
|
|
|
|
}, currentPlayer);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnAudioTracks').addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer && lastPlayerState && lastPlayerState.PlayState) {
|
|
|
|
|
|
|
|
|
|
var currentIndex = lastPlayerState.PlayState.AudioStreamIndex;
|
|
|
|
|
showAudioMenu(context, currentPlayer, e.target, lastPlayerState.NowPlayingItem, currentIndex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnSubtitles').addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer && lastPlayerState && lastPlayerState.PlayState) {
|
|
|
|
|
|
|
|
|
|
var currentIndex = lastPlayerState.PlayState.SubtitleStreamIndex;
|
|
|
|
|
showSubtitleMenu(context, currentPlayer, e.target, lastPlayerState.NowPlayingItem, currentIndex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnChapters').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
//if (currentPlayer && lastPlayerState) {
|
|
|
|
|
|
|
|
|
|
// var currentPositionTicks = lastPlayerState.PlayState.PositionTicks;
|
|
|
|
|
// showChapterMenu(context, lastPlayerState.NowPlayingItem, currentPositionTicks);
|
|
|
|
|
//}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnStop').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.stop();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnPlay').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.unpause();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnPause').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.pause();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnNextTrack').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.nextTrack();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnPreviousTrack').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
if (currentPlayer) {
|
|
|
|
|
currentPlayer.previousTrack();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.nowPlayingPositionSlider').addEventListener('change', function () {
|
|
|
|
|
|
|
|
|
|
var value = this.value;
|
|
|
|
|
|
|
|
|
|
if (currentPlayer && lastPlayerState) {
|
|
|
|
|
|
|
|
|
|
var newPercent = parseFloat(value);
|
|
|
|
|
var newPositionTicks = (newPercent / 100) * lastPlayerState.NowPlayingItem.RunTimeTicks;
|
|
|
|
|
currentPlayer.seek(Math.floor(newPositionTicks));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-13 23:40:21 -07:00
|
|
|
|
context.querySelector('.nowPlayingPositionSlider', context).getBubbleText = function (value) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
var state = lastPlayerState;
|
|
|
|
|
|
|
|
|
|
if (!state || !state.NowPlayingItem || !state.NowPlayingItem.RunTimeTicks) {
|
2016-06-13 23:40:21 -07:00
|
|
|
|
return '--:--';
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ticks = state.NowPlayingItem.RunTimeTicks;
|
|
|
|
|
ticks /= 100;
|
|
|
|
|
ticks *= value;
|
|
|
|
|
|
2016-06-13 23:40:21 -07:00
|
|
|
|
return datetime.getDisplayRunningTime(ticks);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlayerChange() {
|
|
|
|
|
|
|
|
|
|
var context = dlg;
|
|
|
|
|
updateCastIcon(context);
|
|
|
|
|
bindToPlayer(context, MediaController.getCurrentPlayer());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onMessageSubmit(e) {
|
|
|
|
|
|
|
|
|
|
var form = e.target;
|
|
|
|
|
|
|
|
|
|
MediaController.sendCommand({
|
|
|
|
|
Name: 'DisplayMessage',
|
|
|
|
|
Arguments: {
|
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
Header: form.querySelector('#txtMessageTitle').value,
|
|
|
|
|
Text: form.querySelector('#txtMessageText', form).value
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, currentPlayer);
|
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
form.querySelector('input').value = '';
|
2016-02-24 23:38:12 -07:00
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
|
toast('Message sent.');
|
|
|
|
|
});
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onSendStringSubmit(e) {
|
|
|
|
|
|
|
|
|
|
var form = e.target;
|
|
|
|
|
|
|
|
|
|
MediaController.sendCommand({
|
|
|
|
|
Name: 'SendString',
|
|
|
|
|
Arguments: {
|
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
String: form.querySelector('#txtTypeText', form).value
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, currentPlayer);
|
|
|
|
|
|
2016-06-20 10:08:13 -07:00
|
|
|
|
form.querySelector('input').value = '';
|
2016-02-24 23:38:12 -07:00
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
|
toast('Text sent.');
|
|
|
|
|
});
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 07:36:28 -07:00
|
|
|
|
function init(ownerView, context) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-04-18 11:01:50 -07:00
|
|
|
|
require(['css!css/nowplaying.css']);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
bindEvents(context);
|
|
|
|
|
|
|
|
|
|
context.querySelector('.sendMessageForm').addEventListener('submit', onMessageSubmit);
|
|
|
|
|
context.querySelector('.typeTextForm').addEventListener('submit', onSendStringSubmit);
|
|
|
|
|
|
|
|
|
|
context.querySelector('.nowPlayingCastIcon').addEventListener('click', function () {
|
|
|
|
|
MediaController.showPlayerSelection();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.querySelector('.btnExitRemoteControl').addEventListener('click', function () {
|
|
|
|
|
history.back();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//context.querySelector('.btnSlideshow').addEventListener('click', function () {
|
|
|
|
|
// showSlideshowMenu(context);
|
|
|
|
|
//});
|
|
|
|
|
|
2016-05-15 09:30:32 -07:00
|
|
|
|
var mdlTabs = context.querySelector('.libraryViewNav');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
if (AppInfo.enableNowPlayingPageBottomTabs) {
|
2016-05-09 12:27:38 -07:00
|
|
|
|
context.querySelector('.libraryViewNav').classList.add('bottom');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
} else {
|
2016-05-09 12:27:38 -07:00
|
|
|
|
context.querySelector('.libraryViewNav').classList.remove('bottom');
|
2016-02-05 19:47:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-15 09:30:32 -07:00
|
|
|
|
libraryBrowser.configurePaperLibraryTabs(ownerView, mdlTabs, ownerView.querySelectorAll('.pageTabContent'));
|
2016-05-11 07:36:28 -07:00
|
|
|
|
|
2016-05-09 12:27:38 -07:00
|
|
|
|
mdlTabs.addEventListener('tabchange', function (e) {
|
2016-05-19 12:57:30 -07:00
|
|
|
|
|
2016-05-09 12:27:38 -07:00
|
|
|
|
if (e.detail.selectedTabIndex == 2 && playlistNeedsRefresh) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
loadPlaylist(context);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Events.on(MediaController, 'playerchange', onPlayerChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDialogClosed(e) {
|
|
|
|
|
|
|
|
|
|
releaseCurrentPlayer();
|
|
|
|
|
|
|
|
|
|
Events.off(MediaController, 'playerchange', onPlayerChange);
|
|
|
|
|
|
|
|
|
|
lastPlayerState = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onShow(context, tab) {
|
|
|
|
|
|
|
|
|
|
currentImgUrl = null;
|
|
|
|
|
|
|
|
|
|
bindToPlayer(context, MediaController.getCurrentPlayer());
|
|
|
|
|
|
|
|
|
|
updateCastIcon(context);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 07:36:28 -07:00
|
|
|
|
self.init = function (ownerView, context) {
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
|
|
|
|
dlg = context;
|
|
|
|
|
|
2016-02-05 21:30:43 -07:00
|
|
|
|
if (!AppInfo.enableNowPlayingPageBottomTabs) {
|
|
|
|
|
context.querySelector('.btnExitRemoteControl').style.position = 'relative';
|
|
|
|
|
context.querySelector('.topRightContainer').style.position = 'relative';
|
|
|
|
|
}
|
2016-02-05 19:47:06 -07:00
|
|
|
|
|
2016-05-11 07:36:28 -07:00
|
|
|
|
init(ownerView, dlg);
|
2016-02-05 19:47:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.onShow = function () {
|
|
|
|
|
onShow(dlg, window.location.hash);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.destroy = function () {
|
|
|
|
|
onDialogClosed();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
});
|