From 20311f085ff5b3ec53071b8f1bb42726fd31e373 Mon Sep 17 00:00:00 2001 From: Punam Dahiya Date: Wed, 25 Nov 2015 16:06:46 -0800 Subject: [PATCH] Music TV Demo - Handle keydown in player view --- apps/music/js/app.js | 14 +++++++++++++- apps/music/js/endpoint.js | 10 +++++++--- apps/music/views/player-tv/view.js | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/apps/music/js/app.js b/apps/music/js/app.js index 4d08706fc7c8..6da367c28fc5 100644 --- a/apps/music/js/app.js +++ b/apps/music/js/app.js @@ -1,4 +1,4 @@ -/* exported onSearchOpen, onSearchClose */ +/* exported onSearchOpen, onSearchClose, navigateBack */ /* global SERVICE_WORKERS, bridge */ 'use strict'; @@ -292,6 +292,18 @@ function navigateToURL(url, replaceRoot) { window.history.pushState(null, null, url); } +function navigateBack() { + var isPlayerView = viewStack.activeView && + viewStack.activeView.url === VIEWS.PLAYER.URL; + + if (viewStack.views.length > 1) { + // Don't destroy the popped view if it is the "Player" view. + viewStack.popView(!isPlayerView); + window.history.back(); + return; + } +} + function updateOverlays() { if (emptyOverlay) { diff --git a/apps/music/js/endpoint.js b/apps/music/js/endpoint.js index 22f4db4be202..0ed9964edd28 100644 --- a/apps/music/js/endpoint.js +++ b/apps/music/js/endpoint.js @@ -1,6 +1,6 @@ /* global AlbumArtCache, AudioMetadata, Database, LazyLoader, NFCShare, - PlaybackQueue, Remote, bridge, navigateToURL, onSearchOpen, - onSearchClose */ + PlaybackQueue, Remote, bridge, navigateToURL, navigateBack, + onSearchOpen, onSearchClose */ 'use strict'; var audio = null; @@ -466,7 +466,11 @@ function getDatabaseStatus() { } function navigate(url) { - navigateToURL(url); + if(url) { + navigateToURL(url); + } else { + navigateBack(); + } } function searchOpen() { diff --git a/apps/music/views/player-tv/view.js b/apps/music/views/player-tv/view.js index 1bfe198b79ec..46837dd56a14 100644 --- a/apps/music/views/player-tv/view.js +++ b/apps/music/views/player-tv/view.js @@ -45,6 +45,31 @@ var PlayerView = View.extend(function PlayerView() { this.seekBar.elapsedTime = elapsedTime; }); + window.addEventListener('keydown', (evt) => { + if (evt.key === 'Escape') { + // Goes back to music home screen + this.client.method('navigate'); + return; + } + switch (evt.key) { + case 'ArrowLeft': + this.previous(); + break; + case 'ArrowRight': + this.next(); + break; + case 'Enter': + if (this.controls.paused) { + this.play(); + } + else { + this.pause(); + } + break; + } + console.log('player keydown == ', evt); + }); + this.update(); });