chromecast updates

This commit is contained in:
Luke Pulverenti 2014-04-06 13:53:23 -04:00
parent 3f2f3c177e
commit e72026f55c
11 changed files with 582 additions and 200 deletions

View File

@ -78,6 +78,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
return name; return name;
}()); }());
self.deviceName = function () {
return deviceName;
};
self.deviceId = function () { self.deviceId = function () {
return deviceId; return deviceId;
}; };

View File

@ -427,7 +427,7 @@ a.itemTag:hover {
background-size: cover; background-size: cover;
background-position: center 15%; background-position: center 15%;
background-repeat: no-repeat; background-repeat: no-repeat;
height: 550px; height: 570px;
position: relative; position: relative;
} }
@ -482,13 +482,14 @@ a.itemTag:hover {
} }
.itemDetailImage { .itemDetailImage {
max-height: 220px; max-height: 280px;
max-width: 320px; max-width: 320px;
-moz-box-shadow: 0px 0 20px #000; -moz-box-shadow: 0px 0 20px #000;
-webkit-box-shadow: 0px 0 20px #000; -webkit-box-shadow: 0px 0 20px #000;
box-shadow: 0px 0 20px #000; box-shadow: 0px 0 20px #000;
border: solid 1px #222; border: solid 1px #222;
margin-top: -20px; margin-top: -20px;
margin-bottom: 10px;
} }
.noBackdrop .itemDetailImage { .noBackdrop .itemDetailImage {
@ -645,7 +646,7 @@ a.itemTag:hover {
.detailImageProgressContainer { .detailImageProgressContainer {
position: absolute; position: absolute;
bottom: 3px; bottom: 10px;
right: 0; right: 0;
left: 0; left: 0;
text-align: center; text-align: center;

View File

@ -144,7 +144,7 @@
<div class="codecProfiles"></div> <div class="codecProfiles"></div>
</div> </div>
<div class="tabContent tabMediaProfiles"> <div class="tabContent tabMediaProfiles">
<p>Response profiles provide a way to customize responses sent to the device when playing certain kinds of media.</p> <p>Response profiles provide a way to customize information sent to the device when playing certain kinds of media.</p>
<div class="mediaProfiles"></div> <div class="mediaProfiles"></div>
</div> </div>
<br /> <br />

View File

@ -109,32 +109,32 @@
<p id="artist"></p> <p id="artist"></p>
<p class="itemGenres desktopGenres"></p> <p class="itemGenres desktopGenres"></p>
<p class="itemOverview desktopOverview"></p> <p class="itemOverview desktopOverview"></p>
<div class="detailButtonsContainer" style="text-align: left;">
<span id="missingIndicator" style="margin-left: .5em; display: none;">
<span style="background: #cc3333; padding: 5px 1em; border-radius: 5px;">MISSING</span>
</span>
<span id="offlineIndicator" style="margin-left: .5em; display: none;">
<span style="background: #cc3333; padding: 5px 1em; border-radius: 5px;">OFFLINE</span>
</span>
<span id="playButtonContainer" style="display: none;">
<button id="btnPlay" type="button" data-icon="play" data-inline="true" data-mini="true">${ButtonPlay}</button>
</span>
<span id="trailerButtonContainer" style="display: none;">
<button id="btnPlayTrailer" type="button" data-icon="video" data-inline="true" data-mini="true">Trailer</button>
</span>
<span id="externalTrailerButtonContainer" style="display: none;">
<a id="btnPlayExternalTrailer" data-role="button" data-icon="video" data-inline="true" data-mini="true" href="#" target="_blank">Trailer</a>
</span>
<span id="playExternalButtonContainer" style="display: none;">
<a id="btnPlayExternal" data-role="button" data-icon="play" data-inline="true" data-mini="true" href="#" target="_blank">${ButtonPlay}</a>
</span>
<span id="editButtonContainer" style="display: none;">
<a id="btnEdit" data-role="button" data-icon="edit" data-inline="true" data-mini="true" href="#">Edit</a>
</span>
</div>
</td> </td>
</tr> </tr>
</table> </table>
<div class="detailButtonsContainer">
<span id="missingIndicator" style="margin-left: .5em; display: none;">
<span style="background: #cc3333; padding: 5px 1em; border-radius: 5px;">MISSING</span>
</span>
<span id="offlineIndicator" style="margin-left: .5em; display: none;">
<span style="background: #cc3333; padding: 5px 1em; border-radius: 5px;">OFFLINE</span>
</span>
<span id="playButtonContainer" style="display: none;">
<button id="btnPlay" type="button" data-icon="play" data-inline="true" data-mini="true">${ButtonPlay}</button>
</span>
<span id="trailerButtonContainer" style="display: none;">
<button id="btnPlayTrailer" type="button" data-icon="video" data-inline="true" data-mini="true">Trailer</button>
</span>
<span id="externalTrailerButtonContainer" style="display: none;">
<a id="btnPlayExternalTrailer" data-role="button" data-icon="video" data-inline="true" data-mini="true" href="#" target="_blank">Trailer</a>
</span>
<span id="playExternalButtonContainer" style="display: none;">
<a id="btnPlayExternal" data-role="button" data-icon="play" data-inline="true" data-mini="true" href="#" target="_blank">${ButtonPlay}</a>
</span>
<span id="editButtonContainer" style="display: none;">
<a id="btnEdit" data-role="button" data-icon="edit" data-inline="true" data-mini="true" href="#">Edit</a>
</span>
</div>
</div> </div>
<a href="#" id="lnkPreviousItem" class="lnkPreviousItem lnkSibling hide" data-role="button" title="Previous" data-icon="carat-l" data-mini="true" data-inline="true" data-iconpos="notext">Previous</a> <a href="#" id="lnkPreviousItem" class="lnkPreviousItem lnkSibling hide" data-role="button" title="Previous" data-icon="carat-l" data-mini="true" data-inline="true" data-iconpos="notext">Previous</a>
<a href="#" id="lnkNextItem" class="lnkNextItem lnkSibling hide" data-role="button" title="Next" data-icon="carat-r" data-mini="true" data-inline="true" data-iconpos="notext">Next</a> <a href="#" id="lnkNextItem" class="lnkNextItem lnkSibling hide" data-role="button" title="Next" data-icon="carat-r" data-mini="true" data-inline="true" data-iconpos="notext">Next</a>

View File

@ -26,6 +26,8 @@
'ERROR': 'ERROR' 'ERROR': 'ERROR'
}; };
var PlayerName = 'Chromecast';
var CastPlayer = function () { var CastPlayer = function () {
/* device variables */ /* device variables */
@ -37,8 +39,7 @@
this.currentMediaSession = null; this.currentMediaSession = null;
// @type {Number} volume // @type {Number} volume
this.currentVolume = 0.5; this.currentVolume = 0.5;
// @type {Boolean} A flag for autoplay after load
this.autoplay = true;
// @type {string} a chrome.cast.Session object // @type {string} a chrome.cast.Session object
this.session = null; this.session = null;
// @type {PLAYER_STATE} A state for Cast media player // @type {PLAYER_STATE} A state for Cast media player
@ -63,9 +64,6 @@
// @type {Number} A number in milliseconds for minimal progress update // @type {Number} A number in milliseconds for minimal progress update
this.timerStep = 1000; this.timerStep = 1000;
/* media contents from JSON */
this.mediaContents = null;
this.hasReceivers = false; this.hasReceivers = false;
this.initializeCastPlayer(); this.initializeCastPlayer();
@ -89,6 +87,8 @@
return; return;
} }
// v1 Id AE4DA10A
// v2 Id 472F0435
var applicationID = 'AE4DA10A'; var applicationID = 'AE4DA10A';
// request session // request session
@ -97,7 +97,7 @@
this.sessionListener.bind(this), this.sessionListener.bind(this),
this.receiverListener.bind(this)); this.receiverListener.bind(this));
console.log('chrome.cast.initialize'); console.log('chromecast.initialize');
chrome.cast.initialize(apiConfig, this.onInitSuccess.bind(this), this.onError.bind(this)); chrome.cast.initialize(apiConfig, this.onInitSuccess.bind(this), this.onError.bind(this));
}; };
@ -106,7 +106,8 @@
* Callback function for init success * Callback function for init success
*/ */
CastPlayer.prototype.onInitSuccess = function () { CastPlayer.prototype.onInitSuccess = function () {
console.log("init success"); this.isInitialized = true;
console.log("chromecast init success");
}; };
/** /**
@ -127,11 +128,11 @@
this.session = e; this.session = e;
if (this.session) { if (this.session) {
this.deviceState = DEVICE_STATE.ACTIVE; this.deviceState = DEVICE_STATE.ACTIVE;
MediaController.setActivePlayer(PlayerName);
if (this.session.media[0]) { if (this.session.media[0]) {
this.onMediaDiscovered('activeSession', this.session.media[0]); this.onMediaDiscovered('activeSession', this.session.media[0]);
} }
this.session.addUpdateListener(this.sessionUpdateListener.bind(this)); this.session.addUpdateListener(this.sessionUpdateListener.bind(this));
} }
}; };
@ -143,8 +144,6 @@
*/ */
CastPlayer.prototype.receiverListener = function (e) { CastPlayer.prototype.receiverListener = function (e) {
console.log("cast.receiverListener", e);
if (e === 'available') { if (e === 'available') {
console.log("chromecast receiver found"); console.log("chromecast receiver found");
this.hasReceivers = true; this.hasReceivers = true;
@ -166,7 +165,7 @@
this.currentMediaSession = null; this.currentMediaSession = null;
clearInterval(this.timer); clearInterval(this.timer);
MediaController.removeActivePlayer('Chromecast'); MediaController.removeActivePlayer(PlayerName);
} }
}; };
@ -176,7 +175,7 @@
* session request in opt_sessionRequest. * session request in opt_sessionRequest.
*/ */
CastPlayer.prototype.launchApp = function () { CastPlayer.prototype.launchApp = function () {
console.log("launching app..."); console.log("chromecast launching app...");
chrome.cast.requestSession(this.onRequestSessionSuccess.bind(this), this.onLaunchError.bind(this)); chrome.cast.requestSession(this.onRequestSessionSuccess.bind(this), this.onLaunchError.bind(this));
if (this.timer) { if (this.timer) {
clearInterval(this.timer); clearInterval(this.timer);
@ -188,7 +187,7 @@
* @param {Object} e A chrome.cast.Session object * @param {Object} e A chrome.cast.Session object
*/ */
CastPlayer.prototype.onRequestSessionSuccess = function (e) { CastPlayer.prototype.onRequestSessionSuccess = function (e) {
console.log("session success: " + e.sessionId); console.log("chromecast session success: " + e.sessionId);
this.session = e; this.session = e;
this.deviceState = DEVICE_STATE.ACTIVE; this.deviceState = DEVICE_STATE.ACTIVE;
this.session.addUpdateListener(this.sessionUpdateListener.bind(this)); this.session.addUpdateListener(this.sessionUpdateListener.bind(this));
@ -198,7 +197,7 @@
* Callback function for launch error * Callback function for launch error
*/ */
CastPlayer.prototype.onLaunchError = function () { CastPlayer.prototype.onLaunchError = function () {
console.log("launch error"); console.log("chromecast launch error");
this.deviceState = DEVICE_STATE.ERROR; this.deviceState = DEVICE_STATE.ERROR;
Dashboard.alert({ Dashboard.alert({
@ -207,7 +206,7 @@
}); });
MediaController.removeActivePlayer('Chromecast'); MediaController.removeActivePlayer(PlayerName);
}; };
/** /**
@ -228,56 +227,411 @@
this.castPlayerState = PLAYER_STATE.IDLE; this.castPlayerState = PLAYER_STATE.IDLE;
this.currentMediaSession = null; this.currentMediaSession = null;
clearInterval(this.timer); clearInterval(this.timer);
//// continue to play media locally
//console.log("current time: " + this.currentMediaTime);
//this.playMediaLocally(this.currentMediaTime);
}; };
function getMaxVideoAudioChannels() {
return 6;
}
function getMaxAudioChannels() {
return 2;
}
function getMaxVideoLevel() {
return 41;
}
function canDirectStream(mediaType, mediaSource, maxBitrate) {
// If bitrate is unknown don't direct stream
if (!mediaSource.Bitrate || mediaSource.Bitrate > maxBitrate) {
return false;
}
if (mediaType == "Audio") {
return ['mp3', 'aac'].indexOf(mediaSource.Container || '') != -1;
}
else if (mediaType == "Video") {
var videoStream = mediaSource.MediaStreams.filter(function (s) {
return s.Type == 'Video';
})[0];
if (!videoStream) {
return false;
}
if (['high', 'main', 'baseline'].indexOf((videoStream.Profile || '').toLowerCase()) == -1) {
return false;
}
if (!videoStream.Level || videoStream.Level > getMaxVideoLevel()) {
return false;
}
if (!videoStream.Width || videoStream.Width > 1920) {
return false;
}
if (!videoStream.Height || videoStream.Height > 1080) {
return false;
}
return ['mp4'].indexOf(mediaSource.Container || '') != -1;
}
throw new Error('Unrecognized MediaType');
}
function canPlayAudioStreamDirect(audioStream, isVideo) {
var audioCodec = (audioStream.Codec || '').toLowerCase().replace('-', '');
if (audioCodec.indexOf('aac') == -1 &&
audioCodec.indexOf('mp3') == -1 &&
audioCodec.indexOf('mpeg') == -1) {
return false;
}
var maxChannels = isVideo ? getMaxVideoAudioChannels() : getMaxAudioChannels();
if (!audioStream.Channels || audioStream.Channels > maxChannels) {
return false;
}
return true;
}
function isSupportedCodec(mediaType, mediaSource) {
if (mediaType == "Audio") {
return false;
}
else if (mediaType == "Video") {
return mediaSource.MediaStreams.filter(function (m) {
return m.Type == "Video" && (m.Codec || '').toLowerCase() == 'h264';
}).length > 0;
}
throw new Error('Unrecognized MediaType');
}
function getStreamByIndex(streams, type, index) {
return streams.filter(function (s) {
return s.Type == type && s.Index == index;
})[0];
}
function getDefaultAudioStream(mediaStreams, user) {
// Find all audio streams
var audioStreams = mediaStreams.filter(function (stream) {
return stream.Type == "Audio";
}).sort(function (a, b) {
var av = a.IsDefault ? 0 : 1;
var bv = b.IsDefault ? 0 : 1;
return av - bv;
});
if (user.Configuration.AudioLanguagePreference) {
for (var i = 0, length = audioStreams.length; i < length; i++) {
var mediaStream = audioStreams[i];
if (mediaStream.Language == user.Configuration.AudioLanguagePreference) {
return mediaStream.Index;
}
}
}
// Just use the first audio stream
return audioStreams[0];
}
function getMediaSourceInfo(user, item, maxBitrate, mediaSourceId, audioStreamIndex, subtitleStreamIndex) {
var sources = item.MediaSources;
// If a specific stream was requested, filter the list
if (mediaSourceId) {
sources = sources.filter(function (m) {
return m.Id == mediaSourceId;
});
}
// Find first one that can be direct streamed
var source = sources.filter(function (m) {
var audioStreams = m.MediaStreams.filter(function (s) {
return s.Type == 'Audio';
});
var audioStream = mediaSourceId == m.Id && audioStreamIndex != null ? getStreamByIndex(audioStreams, 'Audio', audioStreamIndex) : getDefaultAudioStream(audioStreams, user);
if (!audioStream || !canPlayAudioStreamDirect(audioStream, item.MediaType == 'Video')) {
return false;
}
var subtitleStream = mediaSourceId == m.Id && subtitleStreamIndex != null ? getStreamByIndex(m.MediaStreams, 'Subtitle', subtitleStreamIndex) : null;
if (subtitleStream) {
return false;
}
return canDirectStream(item.MediaType, m, maxBitrate, audioStream);
})[0];
if (source) {
return {
mediaSource: source,
isStatic: true,
streamContainer: source.Container
};
}
// Find first one with supported codec
source = sources.filter(function (m) {
return isSupportedCodec(item.MediaType, m);
})[0];
// Default to first one
return {
mediaSource: source || sources[0],
isStatic: false,
streamContainer: item.MediaType == 'Audio' ? 'mp3' : 'm3u8'
};
}
function getCustomData(item, mediaSourceId, startTimeTicks) {
return {
serverAddress: ApiClient.serverAddress(),
itemId: item.Id,
userId: Dashboard.getCurrentUserId(),
deviceName: ApiClient.deviceName(),
//deviceId: ApiClient.deviceId(),
startTimeTicks: startTimeTicks || 0
};
}
function getMetadata(item) {
var metadata = {};
if (item.Type == 'Episode') {
metadata = new chrome.cast.media.TvShowMediaMetadata();
metadata.type = chrome.cast.media.MetadataType.TV_SHOW;
metadata.episodeTitle = item.Name;
if (item.PremiereDate) {
metadata.originalAirdate = parseISO8601Date(item.PremiereDate).toISOString();
}
metadata.seriesTitle = item.SeriesName;
if (item.IndexNumber != null) {
metadata.episode = metadata.episodeNumber = item.IndexNumber;
}
if (item.ParentIndexNumber != null) {
metadata.season = metadata.seasonNumber = item.ParentIndexNumber;
}
}
else if (item.Type == 'Photo') {
metadata = new chrome.cast.media.PhotoMediaMetadata();
metadata.type = chrome.cast.media.MetadataType.PHOTO;
if (item.PremiereDate) {
metadata.creationDateTime = parseISO8601Date(item.PremiereDate).toISOString();
}
}
else if (item.MediaType == 'Audio') {
metadata = new chrome.cast.media.MusicTrackMediaMetadata();
metadata.type = chrome.cast.media.MetadataType.MUSIC_TRACK;
if (item.ProductionYear) {
metadata.releaseYear = item.ProductionYear;
}
if (item.PremiereDate) {
metadata.releaseDate = parseISO8601Date(item.PremiereDate).toISOString();
}
metadata.songName = item.Name;
metadata.artist = item.Artists & item.Artists.length ? item.Artists[0] : '';
metadata.albumArtist = item.AlbumArtist;
if (item.IndexNumber != null) {
metadata.trackNumber = item.IndexNumber;
}
if (item.ParentIndexNumber != null) {
metadata.discNumber = item.ParentIndexNumber;
}
var composer = (item.People || []).filter(function (p) {
return p.PersonType == 'Type';
})[0];
if (composer) {
metadata.composer = composer.Name;
}
}
else if (item.MediaType == 'Movie') {
metadata = new chrome.cast.media.MovieMediaMetadata();
metadata.type = chrome.cast.media.MetadataType.MUSIC_TRACK;
if (item.ProductionYear) {
metadata.releaseYear = item.ProductionYear;
}
if (item.PremiereDate) {
metadata.releaseDate = parseISO8601Date(item.PremiereDate).toISOString();
}
}
else {
metadata = new chrome.cast.media.GenericMediaMetadata();
metadata.type = chrome.cast.media.MetadataType.GENERIC;
if (item.ProductionYear) {
metadata.releaseYear = item.ProductionYear;
}
if (item.PremiereDate) {
metadata.releaseDate = parseISO8601Date(item.PremiereDate).toISOString();
}
}
metadata.title = item.Name;
if (item.Studios && item.Studios.length) {
metadata.Studio = item.Studios[0];
}
return metadata;
}
function getStreamUrl(item, mediaSourceInfo, startTimeTicks, maxBitrate) {
var url;
if (item.MediaType == 'Audio') {
url = ApiClient.serverAddress() + '/mediabrowser/audio/' + item.Id + '/stream.' + mediaSourceInfo.streamContainer + '?';
url += '&static=' + mediaSourceInfo.isStatic.toString();
url += '&maxaudiochannels=' + getMaxAudioChannels();
if (startTimeTicks) {
url += '&startTimeTicks=' + startTimeTicks.toString();
}
if (maxBitrate) {
url += '&audiobitrate=' + Math.min(maxBitrate, 320000).toString();
}
url += '&audiosamplerate=44100';
url += '&mediasourceid=' + mediaSourceInfo.mediaSource.Id;
return url;
}
else if (item.MediaType == 'Video') {
url = ApiClient.serverAddress() + '/mediabrowser/videos/' + item.Id + '/stream.' + mediaSourceInfo.streamContainer + '?';
url += 'static=' + mediaSourceInfo.isStatic.toString();
url += '&maxaudiochannels=' + getMaxVideoAudioChannels();
if (startTimeTicks) {
url += '&startTimeTicks=' + startTimeTicks.toString();
}
if (maxBitrate) {
var audioRate = 768000;
url += '&audiobitrate=' + audioRate.toString();
url += '&videobitrate=' + (maxBitrate - audioRate).toString();
}
url += '&profile=high';
url += '&level=' + getMaxVideoLevel();
url += '&maxwidth=1920';
url += '&maxheight=1080';
url += '&videoCodec=h264';
url += '&audioCodec=aac';
url += '&audiosamplerate=44100';
url += '&mediasourceid=' + mediaSourceInfo.mediaSource.Id;
return url;
}
throw new Error('Unrecognized MediaType');
}
/** /**
* Loads media into a running receiver application * Loads media into a running receiver application
* @param {Number} mediaIndex An index number to indicate current media content * @param {Number} mediaIndex An index number to indicate current media content
*/ */
CastPlayer.prototype.loadMedia = function (mediaIndex) { CastPlayer.prototype.loadMedia = function (user, item, startTimeTicks, mediaSourceId, audioStreamIndex, subtitleStreamIndex) {
if (!this.session) { if (!this.session) {
console.log("no session"); console.log("no session");
return; return;
} }
//console.log("loading..." + this.mediaContents[mediaIndex]['title']);
//var mediaInfo = new chrome.cast.media.MediaInfo(this.mediaContents[mediaIndex]['sources'][0]);
//mediaInfo.contentType = 'video/mp4';
//var request = new chrome.cast.media.LoadRequest(mediaInfo);
//request.autoplay = this.autoplay;
//if (this.localPlayerState == PLAYER_STATE.PLAYING) {
// request.currentTime = this.localPlayer.currentTime;
//}
//else {
// request.currentTime = 0;
//}
//var payload = {
// "title:": this.mediaContents[0]['title'],
// "thumb": this.mediaContents[0]['thumb']
//};
//var json = { var maxBitrate = 12000000;
// "payload": payload var mediaInfo = getMediaSourceInfo(user, item, maxBitrate, mediaSourceId, audioStreamIndex, subtitleStreamIndex);
//};
//request.customData = json; var streamUrl = getStreamUrl(item, mediaInfo, startTimeTicks, maxBitrate);
//this.castPlayerState = PLAYER_STATE.LOADING; var castMediaInfo = new chrome.cast.media.MediaInfo(streamUrl);
//this.session.loadMedia(request,
// this.onMediaDiscovered.bind(this, 'loadMedia'),
// this.onLoadMediaError.bind(this));
//document.getElementById("media_title").innerHTML = this.mediaContents[this.currentMediaIndex]['title']; castMediaInfo.customData = getCustomData(item, mediaInfo.mediaSource.Id, startTimeTicks);
//document.getElementById("media_subtitle").innerHTML = this.mediaContents[this.currentMediaIndex]['subtitle']; castMediaInfo.metadata = getMetadata(item);
//document.getElementById("media_desc").innerHTML = this.mediaContents[this.currentMediaIndex]['description'];
if (mediaInfo.streamContainer == 'm3u8') {
castMediaInfo.contentType = 'application/x-mpegURL';
} else {
castMediaInfo.contentType = item.MediaType.toLowerCase() + '/' + mediaInfo.streamContainer.toLowerCase();
}
castMediaInfo.streamType = mediaInfo.isStatic ? chrome.cast.media.StreamType.BUFFERED : chrome.cast.media.StreamType.LIVE;
var request = new chrome.cast.media.LoadRequest(castMediaInfo);
request.autoplay = true;
request.currentTime = 0;
this.castPlayerState = PLAYER_STATE.LOADING;
this.session.loadMedia(request,
this.onMediaDiscovered.bind(this, 'loadMedia'),
this.onLoadMediaError.bind(this));
}; };
/** /**
@ -285,16 +639,11 @@
* @param {Object} mediaSession A new media object. * @param {Object} mediaSession A new media object.
*/ */
CastPlayer.prototype.onMediaDiscovered = function (how, mediaSession) { CastPlayer.prototype.onMediaDiscovered = function (how, mediaSession) {
console.log("new media session ID:" + mediaSession.mediaSessionId + ' (' + how + ')'); console.log("chromecast new media session ID:" + mediaSession.mediaSessionId + ' (' + how + ')');
this.currentMediaSession = mediaSession; this.currentMediaSession = mediaSession;
if (how == 'loadMedia') { if (how == 'loadMedia') {
if (this.autoplay) { this.castPlayerState = PLAYER_STATE.PLAYING;
this.castPlayerState = PLAYER_STATE.PLAYING;
}
else {
this.castPlayerState = PLAYER_STATE.LOADED;
}
} }
if (how == 'activeSession') { if (how == 'activeSession') {
@ -327,25 +676,13 @@
// } // }
//} //}
//document.getElementById("duration").innerHTML = duration; //document.getElementById("duration").innerHTML = duration;
//if (this.localPlayerState == PLAYER_STATE.PLAYING) {
// this.localPlayerState == PLAYER_STATE.STOPPED;
// var vi = document.getElementById('video_image')
// vi.style.display = 'block';
// this.localPlayer.style.display = 'none';
// // start progress timer
// this.startProgressTimer(this.incrementMediaTime);
//}
//// update UIs
//this.updateMediaControlUI();
//this.updateDisplayMessage();
}; };
/** /**
* Callback function when media load returns error * Callback function when media load returns error
*/ */
CastPlayer.prototype.onLoadMediaError = function (e) { CastPlayer.prototype.onLoadMediaError = function (e) {
console.log("media error"); console.log("chromecast media error");
this.castPlayerState = PLAYER_STATE.IDLE; this.castPlayerState = PLAYER_STATE.IDLE;
}; };
@ -358,7 +695,7 @@
this.currentMediaTime = 0; this.currentMediaTime = 0;
this.castPlayerState = PLAYER_STATE.IDLE; this.castPlayerState = PLAYER_STATE.IDLE;
} }
console.log("updating media"); console.log("chromecast updating media");
//this.updateProgressBar(e); //this.updateProgressBar(e);
}; };
@ -383,7 +720,7 @@
* Play media in Cast mode * Play media in Cast mode
*/ */
CastPlayer.prototype.playMedia = function () { CastPlayer.prototype.playMedia = function () {
if (!this.currentMediaSession) { if (!this.currentMediaSession) {
return; return;
} }
@ -415,7 +752,7 @@
* Pause media playback in Cast mode * Pause media playback in Cast mode
*/ */
CastPlayer.prototype.pauseMedia = function () { CastPlayer.prototype.pauseMedia = function () {
if (!this.currentMediaSession) { if (!this.currentMediaSession) {
return; return;
} }
@ -433,7 +770,7 @@
* Stop CC playback * Stop CC playback
*/ */
CastPlayer.prototype.stopMedia = function () { CastPlayer.prototype.stopMedia = function () {
if (!this.currentMediaSession) { if (!this.currentMediaSession) {
return; return;
} }
@ -450,7 +787,7 @@
* @param {Boolean} mute A boolean * @param {Boolean} mute A boolean
*/ */
CastPlayer.prototype.setReceiverVolume = function (mute) { CastPlayer.prototype.setReceiverVolume = function (mute) {
if (!this.currentMediaSession) { if (!this.currentMediaSession) {
return; return;
} }
@ -515,18 +852,6 @@
var pw = pos; var pw = pos;
} }
if (this.localPlayerState == PLAYER_STATE.PLAYING || this.localPlayerState == PLAYER_STATE.PAUSED) {
this.localPlayer.currentTime = curr;
this.currentMediaTime = curr;
this.localPlayer.play();
}
if (this.localPlayerState == PLAYER_STATE.PLAYING || this.localPlayerState == PLAYER_STATE.PAUSED
|| this.castPlayerState == PLAYER_STATE.PLAYING || this.castPlayerState == PLAYER_STATE.PAUSED) {
p.style.width = pw + 'px';
pi.style.marginLeft = pp + 'px';
}
if (this.castPlayerState != PLAYER_STATE.PLAYING && this.castPlayerState != PLAYER_STATE.PAUSED) { if (this.castPlayerState != PLAYER_STATE.PLAYING && this.castPlayerState != PLAYER_STATE.PAUSED) {
return; return;
} }
@ -616,24 +941,48 @@
var castPlayer = new CastPlayer(); var castPlayer = new CastPlayer();
window.CastPlayer = castPlayer;
function chromecastPlayer() { function chromecastPlayer() {
var self = this; var self = this;
self.name = 'Chromecast'; self.name = PlayerName;
self.play = function (options) { self.play = function (options) {
if (options.items) {
Dashboard.getCurrentUser().done(function (user) {
castPlayer.loadMedia(user, options.items[0], options.startTimeTicks);
});
} else {
var userId = Dashboard.getCurrentUserId();
var query = {};
query.Limit = query.Limit || 100;
query.Fields = "MediaSources,Chapters";
query.ExcludeLocationTypes = "Virtual";
query.Ids = options.ids.join(',');
ApiClient.getItems(userId, query).done(function (result) {
options.items = result.Items;
self.play(options);
});
}
}; };
self.shuffle = function (id) { self.shuffle = function (id) {
self.play({ ids: [id] });
}; };
self.instantMix = function (id) { self.instantMix = function (id) {
self.play({ ids: [id] });
}; };
self.queue = function (options) { self.queue = function (options) {
@ -645,7 +994,7 @@
}; };
self.stop = function () { self.stop = function () {
CastPlayer.stop(); castPlayer.stop();
}; };
self.canQueueMediaType = function (mediaType) { self.canQueueMediaType = function (mediaType) {
@ -653,57 +1002,55 @@
return false; return false;
}; };
self.mute = function() { self.mute = function () {
CastPlayer.mute(); castPlayer.mute();
}; };
self.unMute = function () { self.unMute = function () {
CastPlayer.unMute(); castPlayer.unMute();
}; };
self.toggleMute = function () { self.toggleMute = function () {
CastPlayer.toggleMute(); castPlayer.toggleMute();
}; };
self.getTargets = function () { self.getTargets = function () {
var targets = []; var targets = [];
var appName = null; targets.push(self.getCurrentTargetInfo());
//if (CastPlayer.session && CastPlayer.session.receiver && CastPlayer.session.friendlyName) {
// appName = CastPlayer.session.friendlyName;
//}
//if (true) {
// targets.push({
// name: "Chromecast",
// id: "Chromecast",
// playerName: self.name,
// playableMediaTypes: ["Audio", "Video"],
// isLocalPlayer: false,
// appName: appName
// });
//}
return targets; return targets;
}; };
self.getCurrentTargetInfo = function () {
var appName = null;
if (castPlayer.session && castPlayer.session.receiver && castPlayer.session.friendlyName) {
appName = castPlayer.session.friendlyName;
}
return {
name: PlayerName,
id: PlayerName,
playerName: self.name,
playableMediaTypes: ["Audio", "Video"],
isLocalPlayer: false,
appName: appName
};
};
} }
MediaController.registerPlayer(new chromecastPlayer()); MediaController.registerPlayer(new chromecastPlayer());
$(document).on('headercreated', ".libraryPage", function () {
var page = this;
//castPlayer.updateMediaControlUI();
});
$(MediaController).on('playerchange', function () { $(MediaController).on('playerchange', function () {
if (MediaController.getPlayerInfo().name == 'Chromecast') { if (MediaController.getPlayerInfo().name == PlayerName) {
window.CastPlayer.launchApp();
if (castPlayer.deviceState != DEVICE_STATE.ACTIVE && castPlayer.isInitialized) {
castPlayer.launchApp();
}
} }
}); });

View File

@ -2,6 +2,22 @@
var currentItem; var currentItem;
function getExternalPlayUrl(item) {
var providerIds = item.ProviderIds || {};
if (item.GameSystem == "Nintendo" && item.MediaType == "Game" && providerIds.NesBox && providerIds.NesBoxRom) {
return "http://nesbox.com/game/" + providerIds.NesBox + '/rom/' + providerIds.NesBoxRom;
}
if (item.GameSystem == "Super Nintendo" && item.MediaType == "Game" && providerIds.NesBox && providerIds.NesBoxRom) {
return "http://snesbox.com/game/" + providerIds.NesBox + '/rom/' + providerIds.NesBoxRom;
}
return null;
}
function reload(page) { function reload(page) {
var id = getParameterByName('id'); var id = getParameterByName('id');
@ -117,22 +133,6 @@
$('#btnEdit', page).attr('href', "edititemmetadata.html?id=" + id); $('#btnEdit', page).attr('href', "edititemmetadata.html?id=" + id);
} }
function getExternalPlayUrl(item) {
if (item.GameSystem == "Nintendo" && item.MediaType == "Game" && item.ProviderIds.NesBox && item.ProviderIds.NesBoxRom) {
return "http://nesbox.com/game/" + item.ProviderIds.NesBox + '/rom/' + item.ProviderIds.NesBoxRom;
}
if (item.GameSystem == "Super Nintendo" && item.MediaType == "Game" && item.ProviderIds.NesBox && item.ProviderIds.NesBoxRom) {
return "http://snesbox.com/game/" + item.ProviderIds.NesBox + '/rom/' + item.ProviderIds.NesBoxRom;
}
return null;
};
function setPeopleHeader(page, item) { function setPeopleHeader(page, item) {
if (item.Type == "Audio" || item.Type == "MusicAlbum" || item.MediaType == "Book" || item.MediaType == "Photo") { if (item.Type == "Audio" || item.Type == "MusicAlbum" || item.MediaType == "Book" || item.MediaType == "Photo") {

View File

@ -20,14 +20,14 @@
loadSavedQueryValues: function (key, query) { loadSavedQueryValues: function (key, query) {
//var values = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId()); var values = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId());
//if (values) { if (values) {
// values = JSON.parse(values); values = JSON.parse(values);
// return $.extend(query, values); return $.extend(query, values);
//} }
return query; return query;
}, },
@ -1397,7 +1397,7 @@
var url; var url;
var imageHeight = 440; var imageHeight = 600;
if (imageTags.Primary) { if (imageTags.Primary) {

View File

@ -43,14 +43,14 @@
$(self).trigger('playerchange'); $(self).trigger('playerchange');
}; };
self.setLocalPlayerActive = function() { self.setDefaultPlayerActive = function() {
self.setActivePlayer(self.getLocalPlayer()); self.setActivePlayer(self.getDefaultPlayer());
}; };
self.removeActivePlayer = function (name) { self.removeActivePlayer = function (name) {
if (self.getPlayerInfo().name == name) { if (self.getPlayerInfo().name == name) {
self.setLocalPlayerActive(); self.setDefaultPlayerActive();
} }
}; };
@ -163,6 +163,17 @@
return p.isLocalPlayer; return p.isLocalPlayer;
})[0]; })[0];
}; };
self.getDefaultPlayer = function () {
return currentPlayer.isLocalPlayer ?
currentPlayer :
players.filter(function (p) {
return p.isDefaultPlayer;
})[0];
};
} }
window.MediaController = new mediaController(); window.MediaController = new mediaController();
@ -188,6 +199,12 @@
} }
} }
else if (msg.MessageType === "ServerShuttingDown") {
MediaController.setDefaultPlayerActive();
}
else if (msg.MessageType === "ServerRestarting") {
MediaController.setDefaultPlayerActive();
}
else if (msg.MessageType === "Playstate") { else if (msg.MessageType === "Playstate") {
if (msg.Data.Command === 'Stop') { if (msg.Data.Command === 'Stop') {

View File

@ -32,7 +32,7 @@
self.remoteFullscreen = function () { self.remoteFullscreen = function () {
var videoControls = $("#videoControls"); var videoControls = $("#videoControls");
if (remoteFullscreen) { if (remoteFullscreen) {
exitFullScreenToWindow(); exitFullScreenToWindow();
videoControls.removeClass("inactive"); videoControls.removeClass("inactive");
@ -403,7 +403,7 @@
}; };
function getAudioTracksHtml() { function getAudioTracksHtml() {
var streams = currentMediaSource.MediaStreams.filter(function (currentStream) { var streams = currentMediaSource.MediaStreams.filter(function (currentStream) {
return currentStream.Type == "Audio"; return currentStream.Type == "Audio";
}); });
@ -625,9 +625,16 @@
function getInitialAudioStreamIndex(mediaStreams, user) { function getInitialAudioStreamIndex(mediaStreams, user) {
// Find all audio streams with at least one channel // Find all audio streams
var audioStreams = mediaStreams.filter(function (stream) { var audioStreams = mediaStreams.filter(function (stream) {
return stream.Type == "Audio" && stream.Channels; return stream.Type == "Audio";
}).sort(function (a, b) {
var av = a.IsDefault ? 0 : 1;
var bv = b.IsDefault ? 0 : 1;
return av - bv;
}); });
if (user.Configuration.AudioLanguagePreference) { if (user.Configuration.AudioLanguagePreference) {
@ -643,9 +650,9 @@
} }
// Just use the first audio stream // Just use the first audio stream
return audioStreams.length ? audioStreams[0].Index : null; return audioStreams[0];
}; };
function getVideoQualityOptions(mediaStreams) { function getVideoQualityOptions(mediaStreams) {
var videoStream = mediaStreams.filter(function (stream) { var videoStream = mediaStreams.filter(function (stream) {
@ -753,9 +760,6 @@
})[0]; })[0];
m3U8Quality = $.extend(m3U8Quality, self.getFinalVideoParams(mediaSource, mp4Quality.maxWidth, mp4Quality.bitrate, baseParams.AudioStreamIndex, baseParams.SubtitleStreamIndex, '.mp4')); m3U8Quality = $.extend(m3U8Quality, self.getFinalVideoParams(mediaSource, mp4Quality.maxWidth, mp4Quality.bitrate, baseParams.AudioStreamIndex, baseParams.SubtitleStreamIndex, '.mp4'));
// Webm must be ahead of mp4 due to the issue of mp4 playing too fast in chrome
var prioritizeWebmOverH264 = $.browser.chrome || $.browser.msie;
var isStatic = mp4Quality.isStatic; var isStatic = mp4Quality.isStatic;
self.startTimeTicksOffset = isStatic ? 0 : startPosition || 0; self.startTimeTicksOffset = isStatic ? 0 : startPosition || 0;
@ -815,18 +819,15 @@
html += '<source type="application/x-mpegURL" src="' + hlsVideoUrl + '" />'; html += '<source type="application/x-mpegURL" src="' + hlsVideoUrl + '" />';
} }
if (prioritizeWebmOverH264 && !isStatic) { // Have to put webm ahead of mp4 because it will play in fast forward in chrome
// And firefox doesn't like fragmented mp4
if (!isStatic) {
html += '<source type="video/webm" src="' + webmVideoUrl + '" />'; html += '<source type="video/webm" src="' + webmVideoUrl + '" />';
} }
html += '<source type="video/mp4" src="' + mp4VideoUrl + '" />'; html += '<source type="video/mp4" src="' + mp4VideoUrl + '" />';
if (!prioritizeWebmOverH264 && !isStatic) {
html += '<source type="video/webm" src="' + webmVideoUrl + '" />';
}
html += '</video>'; html += '</video>';
var mediaPlayer = $("#mediaPlayer").show(); var mediaPlayer = $("#mediaPlayer").show();
@ -1016,7 +1017,7 @@
if (e.keyCode == 27) { if (e.keyCode == 27) {
self.stop(); self.stop();
$(this).unbind("keyup.enhancePlayer"); $(this).off("keyup.enhancePlayer");
} }
}); });

View File

@ -24,6 +24,7 @@
self.playlist = []; self.playlist = [];
self.isLocalPlayer = true; self.isLocalPlayer = true;
self.isDefaultPlayer = true;
self.name = 'Html5 Player'; self.name = 'Html5 Player';
self.getTargets = function () { self.getTargets = function () {
@ -115,7 +116,7 @@
} }
// Chrome or IE with plugin installed // Chrome or IE with plugin installed
if (canPlayWebm() && !$.browser.mozilla) { if (canPlayWebm()) {
return '.webm'; return '.webm';
} }
@ -232,7 +233,7 @@
return false; return false;
} }
if (mediaSource.VideoType != "VideoFile" || mediaSource.LocationType != "FileSystem") { if (mediaSource.VideoType != "VideoFile") {
console.log('Transcoding because the content is not a video file'); console.log('Transcoding because the content is not a video file');
return false; return false;
} }
@ -257,10 +258,7 @@
return false; return false;
} }
var videoBitrate = videoStream.BitRate || 0; if (!mediaSource.Bitrate || mediaSource.Bitrate > bitrate) {
var audioBitrate = audioStream ? audioStream.BitRate || 0 : null;
if ((videoBitrate + audioBitrate) > bitrate) {
console.log('Transcoding because bitrate is too high'); console.log('Transcoding because bitrate is too high');
return false; return false;
} }

View File

@ -424,7 +424,7 @@
PlayCommand: playType PlayCommand: playType
}; };
if (options.startPositionTicks) { if (options.startPositionTicks) {
remoteOptions.startPositionTicks = options.startPositionTicks; remoteOptions.startPositionTicks = options.startPositionTicks;
} }
@ -523,4 +523,18 @@
MediaController.registerPlayer(new remoteControlPlayer()); MediaController.registerPlayer(new remoteControlPlayer());
function onWebSocketMessageReceived(e, msg) {
if (msg.MessageType === "SessionEnded") {
console.log("Server reports another session ended");
if (MediaController.getPlayerInfo().id == msg.Data.Id) {
MediaController.setDefaultPlayerActive();
}
}
}
$(ApiClient).on("websocketmessage", onWebSocketMessageReceived);
})(window, document, jQuery); })(window, document, jQuery);