fix album save in metadata manager
This commit is contained in:
parent
9336922f29
commit
adacfbbab3
15 changed files with 353 additions and 90 deletions
312
dashboard-ui/thirdparty/cordova/chromecast.js
vendored
312
dashboard-ui/thirdparty/cordova/chromecast.js
vendored
|
@ -2,7 +2,10 @@
|
|||
|
||||
var PlayerName = "Chromecast";
|
||||
var ApplicationID = "F4EB2E8E";
|
||||
var currentDevice;
|
||||
var currentPairingDeviceId;
|
||||
var currentPairedDeviceId;
|
||||
var currentDeviceFriendlyName;
|
||||
var currentWebAppSession;
|
||||
|
||||
function chromecastPlayer() {
|
||||
|
||||
|
@ -34,8 +37,6 @@
|
|||
|
||||
console.log('cc: playbackstart');
|
||||
|
||||
castPlayer.initializeCastPlayer();
|
||||
|
||||
var state = self.getPlayerStateInternal(data);
|
||||
$(self).trigger("playbackstart", [state]);
|
||||
});
|
||||
|
@ -59,6 +60,54 @@
|
|||
$(self).trigger("positionchange", [state]);
|
||||
});
|
||||
|
||||
var endpointInfo;
|
||||
function getEndpointInfo() {
|
||||
|
||||
if (endpointInfo) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
deferred.resolveWith(null, [endpointInfo]);
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
return ApiClient.getJSON(ApiClient.getUrl('System/Endpoint')).done(function (info) {
|
||||
|
||||
endpointInfo = info;
|
||||
});
|
||||
}
|
||||
|
||||
function sendMessageToDevice(message) {
|
||||
|
||||
var bitrateSetting = AppSettings.maxChromecastBitrate();
|
||||
|
||||
message = $.extend(message, {
|
||||
userId: Dashboard.getCurrentUserId(),
|
||||
deviceId: ApiClient.deviceId(),
|
||||
accessToken: ApiClient.accessToken(),
|
||||
serverAddress: ApiClient.serverAddress(),
|
||||
maxBitrate: bitrateSetting,
|
||||
receiverName: currentDeviceFriendlyName
|
||||
});
|
||||
|
||||
getEndpointInfo().done(function (endpoint) {
|
||||
|
||||
if (endpoint.IsLocal || endpoint.IsInNetwork) {
|
||||
ApiClient.getSystemInfo().done(function (info) {
|
||||
|
||||
message.serverAddress = info.LocalAddress;
|
||||
sendMessageInternal(message);
|
||||
});
|
||||
} else {
|
||||
sendMessageInternal(message);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function sendMessageInternal(message) {
|
||||
currentWebAppSession.sendText(JSON.stringify(message));
|
||||
}
|
||||
|
||||
self.play = function (options) {
|
||||
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
|
@ -97,15 +146,34 @@
|
|||
return;
|
||||
}
|
||||
|
||||
castPlayer.loadMedia(options, command);
|
||||
// Convert the items to smaller stubs to send the minimal amount of information
|
||||
options.items = options.items.map(function (i) {
|
||||
|
||||
return {
|
||||
Id: i.Id,
|
||||
Name: i.Name,
|
||||
Type: i.Type,
|
||||
MediaType: i.MediaType,
|
||||
IsFolder: i.IsFolder
|
||||
};
|
||||
});
|
||||
|
||||
sendMessageToDevice({
|
||||
options: options,
|
||||
command: command
|
||||
});
|
||||
};
|
||||
|
||||
self.unpause = function () {
|
||||
castPlayer.playMedia();
|
||||
sendMessageToDevice({
|
||||
command: 'unpause'
|
||||
});
|
||||
};
|
||||
|
||||
self.pause = function () {
|
||||
castPlayer.pauseMedia();
|
||||
sendMessageToDevice({
|
||||
command: 'pause'
|
||||
});
|
||||
};
|
||||
|
||||
self.shuffle = function (id) {
|
||||
|
@ -153,19 +221,23 @@
|
|||
};
|
||||
|
||||
self.stop = function () {
|
||||
castPlayer.stopMedia();
|
||||
sendMessageToDevice({
|
||||
command: 'stop'
|
||||
});
|
||||
};
|
||||
|
||||
self.displayContent = function (options) {
|
||||
|
||||
castPlayer.sendMessage({
|
||||
sendMessageToDevice({
|
||||
options: options,
|
||||
command: 'DisplayContent'
|
||||
});
|
||||
};
|
||||
|
||||
self.mute = function () {
|
||||
castPlayer.mute();
|
||||
sendMessageToDevice({
|
||||
command: 'mute'
|
||||
});
|
||||
};
|
||||
|
||||
self.unMute = function () {
|
||||
|
@ -216,19 +288,39 @@
|
|||
return target;
|
||||
}
|
||||
|
||||
function isChromecast(name) {
|
||||
|
||||
var validTokens = ['nexusplayer', 'chromecast', 'eurekadongle'];
|
||||
|
||||
return validTokens.filter(function (t) {
|
||||
|
||||
return name.toLowerCase().replace(' ', '').indexOf(t) != -1;
|
||||
|
||||
}).length > 0;
|
||||
}
|
||||
|
||||
self.getTargets = function () {
|
||||
|
||||
var manager = ConnectSDK.discoveryManager;
|
||||
|
||||
return manager.getDeviceList().map(convertDeviceToTarget);
|
||||
return manager.getDeviceList().filter(function (d) {
|
||||
|
||||
return isChromecast(d.getModelName()) || isChromecast(d.getFriendlyName());
|
||||
|
||||
}).map(convertDeviceToTarget);
|
||||
};
|
||||
|
||||
self.seek = function (position) {
|
||||
castPlayer.seekMedia(position);
|
||||
sendMessageToDevice({
|
||||
options: {
|
||||
position: position
|
||||
},
|
||||
command: 'Seek'
|
||||
});
|
||||
};
|
||||
|
||||
self.setAudioStreamIndex = function (index) {
|
||||
castPlayer.sendMessage({
|
||||
sendMessageToDevice({
|
||||
options: {
|
||||
index: index
|
||||
},
|
||||
|
@ -237,7 +329,7 @@
|
|||
};
|
||||
|
||||
self.setSubtitleStreamIndex = function (index) {
|
||||
castPlayer.sendMessage({
|
||||
sendMessageToDevice({
|
||||
options: {
|
||||
index: index
|
||||
},
|
||||
|
@ -246,14 +338,14 @@
|
|||
};
|
||||
|
||||
self.nextTrack = function () {
|
||||
castPlayer.sendMessage({
|
||||
sendMessageToDevice({
|
||||
options: {},
|
||||
command: 'NextTrack'
|
||||
});
|
||||
};
|
||||
|
||||
self.previousTrack = function () {
|
||||
castPlayer.sendMessage({
|
||||
sendMessageToDevice({
|
||||
options: {},
|
||||
command: 'PreviousTrack'
|
||||
});
|
||||
|
@ -289,7 +381,12 @@
|
|||
vol = Math.min(vol, 100);
|
||||
vol = Math.max(vol, 0);
|
||||
|
||||
castPlayer.setReceiverVolume(false, (vol / 100));
|
||||
sendMessageToDevice({
|
||||
options: {
|
||||
volume: (vol / 100)
|
||||
},
|
||||
command: 'SetVolume'
|
||||
});
|
||||
};
|
||||
|
||||
self.getPlayerState = function () {
|
||||
|
@ -314,33 +411,186 @@
|
|||
return data;
|
||||
};
|
||||
|
||||
function onMessage(message) {
|
||||
|
||||
if (message.type == 'playbackerror') {
|
||||
|
||||
var errorCode = message.data;
|
||||
|
||||
setTimeout(function () {
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('MessagePlaybackError' + errorCode),
|
||||
title: Globalize.translate('HeaderPlaybackError')
|
||||
});
|
||||
}, 300);
|
||||
|
||||
}
|
||||
else if (message.type == 'connectionerror') {
|
||||
|
||||
setTimeout(function () {
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('MessageChromecastConnectionError'),
|
||||
title: Globalize.translate('HeaderError')
|
||||
});
|
||||
}, 300);
|
||||
|
||||
}
|
||||
else if (message.type && message.type.indexOf('playback') == 0) {
|
||||
$(castPlayer).trigger(message.type, [message.data]);
|
||||
}
|
||||
}
|
||||
|
||||
function onSessionConnected(device, session) {
|
||||
|
||||
// hold on to a reference
|
||||
currentWebAppSession = session.acquire();
|
||||
|
||||
session.connect().success(function () {
|
||||
|
||||
console.log('session.connect succeeded');
|
||||
|
||||
MediaController.setActivePlayer(PlayerName, convertDeviceToTarget(device));
|
||||
currentDeviceFriendlyName = device.getFriendlyName();
|
||||
currentPairedDeviceId = device.getId();
|
||||
|
||||
$(castPlayer).trigger('connect');
|
||||
|
||||
sendMessageToDevice({
|
||||
options: {},
|
||||
command: 'Identify'
|
||||
});
|
||||
});
|
||||
|
||||
session.on('message', function (message) {
|
||||
// message could be either a string or an object
|
||||
if (typeof message === 'string') {
|
||||
onMessage(JSON.parse(message));
|
||||
} else {
|
||||
onMessage(message);
|
||||
}
|
||||
});
|
||||
|
||||
session.on('disconnect', function () {
|
||||
|
||||
console.log("session disconnected");
|
||||
|
||||
if (currentPairedDeviceId == device.getId()) {
|
||||
onDisconnected();
|
||||
MediaController.removeActivePlayer(PlayerName);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function onDisconnected() {
|
||||
currentWebAppSession = null;
|
||||
currentPairedDeviceId = null;
|
||||
currentDeviceFriendlyName = null;
|
||||
}
|
||||
|
||||
function launchWebApp(device) {
|
||||
device.getWebAppLauncher().launchWebApp(ApplicationID).success(function (session) {
|
||||
|
||||
console.log('launchWebApp success. calling onSessionConnected');
|
||||
onSessionConnected(device, session);
|
||||
|
||||
}).error(function (err) {
|
||||
|
||||
console.log('launchWebApp error: ' + JSON.stringify(err) + '. calling joinWebApp');
|
||||
|
||||
device.getWebAppLauncher().joinWebApp(ApplicationID).success(function (session) {
|
||||
|
||||
console.log('joinWebApp success. calling onSessionConnected');
|
||||
onSessionConnected(device, session);
|
||||
|
||||
}).error(function (err1) {
|
||||
|
||||
console.log('joinWebApp error:' + JSON.stringify(err1));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function onDeviceReady(device) {
|
||||
|
||||
if (currentPairingDeviceId != device.getId()) {
|
||||
console.log('device ready fired for a different device. ignoring.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('calling launchWebApp');
|
||||
|
||||
setTimeout(function () {
|
||||
|
||||
launchWebApp(device);
|
||||
|
||||
}, 0);
|
||||
}
|
||||
|
||||
var boundHandlers = [];
|
||||
|
||||
self.tryPair = function (target) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
deferred.resolve();
|
||||
|
||||
var manager = ConnectSDK.discoveryManager;
|
||||
|
||||
var device = manager.getDeviceList().filter(function (d) {
|
||||
|
||||
return d.getId() == target.id;
|
||||
})[0];
|
||||
|
||||
if (device) {
|
||||
|
||||
var deviceId = device.getId();
|
||||
currentPairingDeviceId = deviceId;
|
||||
|
||||
console.log('Will attempt to connect to Chromecast');
|
||||
|
||||
if (device.isReady()) {
|
||||
console.log('Device is already ready, calling onDeviceReady');
|
||||
onDeviceReady(device);
|
||||
} else {
|
||||
|
||||
console.log('Binding device ready handler');
|
||||
|
||||
if (boundHandlers.indexOf(deviceId) == -1) {
|
||||
|
||||
boundHandlers.push(deviceId);
|
||||
device.on("ready", function () {
|
||||
console.log('device.ready fired');
|
||||
onDeviceReady(device);
|
||||
});
|
||||
}
|
||||
|
||||
console.log('Calling device.connect');
|
||||
device.connect();
|
||||
}
|
||||
//deferred.resolve();
|
||||
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
}
|
||||
|
||||
function onDeviceLost() {
|
||||
$(MediaController).on('playerchange', function (e, newPlayer, newTarget) {
|
||||
|
||||
if (newPlayer.name != PlayerName || newTarget.id != currentPairedDeviceId) {
|
||||
if (currentWebAppSession) {
|
||||
currentWebAppSession.disconnect();
|
||||
onDisconnected();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initSdk() {
|
||||
|
||||
var manager = ConnectSDK.discoveryManager;
|
||||
|
||||
manager.addListener('devicelost', onDeviceLost);
|
||||
|
||||
MediaController.registerPlayer(new chromecastPlayer());
|
||||
|
||||
$(MediaController).on('playerchange', function () {
|
||||
|
||||
if (MediaController.getPlayerInfo().name == PlayerName) {
|
||||
|
||||
// launch app if needed
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initSdk();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue