when connected to chromecast make thehardware volume buttons change the chromecast device volume + fix volumeUp and columeDown missing var's
This commit is contained in:
parent
f6f51d79cc
commit
4baad878ac
1 changed files with 21 additions and 6 deletions
|
@ -220,7 +220,9 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
|||
this.session = null;
|
||||
this.deviceState = DEVICE_STATE.IDLE;
|
||||
this.castPlayerState = PLAYER_STATE.IDLE;
|
||||
|
||||
document.removeEventListener("volumeupbutton", onVolumeUpKeyDown, false);
|
||||
document.removeEventListener("volumedownbutton", onVolumeDownKeyDown, false);
|
||||
|
||||
//console.log('sessionUpdateListener: setting currentMediaSession to null');
|
||||
this.currentMediaSession = null;
|
||||
|
||||
|
@ -258,6 +260,9 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
|||
this.session.addMediaListener(this.sessionMediaListener.bind(this));
|
||||
this.session.addUpdateListener(this.sessionUpdateListener.bind(this));
|
||||
|
||||
document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);
|
||||
document.addEventListener("volumedownbutton", onVolumeDownKeyDown, false);
|
||||
|
||||
events.trigger(this, 'connect');
|
||||
|
||||
this.sendMessage({
|
||||
|
@ -266,6 +271,14 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
|||
});
|
||||
};
|
||||
|
||||
function onVolumeUpKeyDown() {
|
||||
playbackManager.volumeUp();
|
||||
}
|
||||
|
||||
function onVolumeDownKeyDown() {
|
||||
playbackManager.volumeDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* session update listener
|
||||
*/
|
||||
|
@ -305,6 +318,8 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
|||
//console.log(message);
|
||||
this.deviceState = DEVICE_STATE.IDLE;
|
||||
this.castPlayerState = PLAYER_STATE.IDLE;
|
||||
document.removeEventListener("volumeupbutton", onVolumeUpKeyDown, false);
|
||||
document.removeEventListener("volumedownbutton", onVolumeDownKeyDown, false);
|
||||
|
||||
//console.log('onStopAppSuccess: setting currentMediaSession to null');
|
||||
this.currentMediaSession = null;
|
||||
|
@ -786,13 +801,13 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
|||
});
|
||||
};
|
||||
|
||||
ChromecastPlayer.prototype.volumeDown = function () {
|
||||
vol = this._castPlayer.session.receiver.volume.level;
|
||||
ChromecastPlayer.prototype.volumeDown = function () {
|
||||
var vol = this._castPlayer.session.receiver.volume.level;
|
||||
if (vol == null)
|
||||
{
|
||||
vol = 0.5;
|
||||
}
|
||||
vol -= 0.02;
|
||||
vol -= 0.05;
|
||||
vol = Math.max(vol, 0);
|
||||
|
||||
this._castPlayer.session.setReceiverVolumeLevel(vol);
|
||||
|
@ -811,12 +826,12 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', '
|
|||
};
|
||||
|
||||
ChromecastPlayer.prototype.volumeUp = function () {
|
||||
vol = this._castPlayer.session.receiver.volume.level;
|
||||
var vol = this._castPlayer.session.receiver.volume.level;
|
||||
if (vol == null)
|
||||
{
|
||||
vol = 0.5;
|
||||
}
|
||||
vol += 0.02;
|
||||
vol += 0.05;
|
||||
vol = Math.min(vol, 1);
|
||||
|
||||
this._castPlayer.session.setReceiverVolumeLevel(vol);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue