var MediaPlayer = {
canPlay: function (item) {
if (item.MediaType === "Video") {
var media = document.createElement('video');
if (media.canPlayType) {
return media.canPlayType('video/mp2t').replace(/no/, '') || media.canPlayType('video/webm').replace(/no/, '') || media.canPlayType('video/ogv').replace(/no/, '');
}
return false;
}
if (item.MediaType === "Audio") {
var media = document.createElement('audio');
if (media.canPlayType) {
return media.canPlayType('audio/mpeg').replace(/no/, '') || media.canPlayType('audio/aac').replace(/no/, '');
}
return false;
}
return false;
},
play: function (items) {
if (MediaPlayer.isPlaying()) {
MediaPlayer.stop();
}
var item = items[0];
var mediaElement;
if (item.MediaType === "Video") {
mediaElement = MediaPlayer.playVideo(items);
}
else if (item.MediaType === "Audio") {
mediaElement = MediaPlayer.playAudio(items);
}
if (!mediaElement) {
return;
}
MediaPlayer.mediaElement = mediaElement;
var nowPlayingBar = $('#nowPlayingBar').show();
if (items.length > 1) {
$('#previousTrackButton', nowPlayingBar)[0].disabled = false;
$('#nextTrackButton', nowPlayingBar)[0].disabled = false;
} else {
$('#previousTrackButton', nowPlayingBar)[0].disabled = true;
$('#nextTrackButton', nowPlayingBar)[0].disabled = true;
}
},
playAudio: function (items) {
var item = items[0];
var baseParams = {
id: item.Id,
audioChannels: 2,
audioBitrate: 128000
};
var mp3Url = ApiClient.getUrl('audio.mp3', $.extend({}, baseParams, {
audioCodec: 'mp3'
}));
var aacUrl = ApiClient.getUrl('audio.aac', $.extend({}, baseParams, {
audioCodec: 'aac'
}));
var webmUrl = ApiClient.getUrl('audio.webma', $.extend({}, baseParams, {
audioCodec: 'Vorbis'
}));
var oggUrl = ApiClient.getUrl('audio.oga', $.extend({}, baseParams, {
audioCodec: 'Vorbis'
}));
var html = '';
html += '';
html += '