Commit e54e8193 authored by sschmitz@chromium.org's avatar sschmitz@chromium.org

Ash: Support "Next Song", "Previous Song", "Play/Pause" Multi Media buttons

in our Media Player that is part of the File Manager right now.

Added shortcut handlers and plumbing to the Audio and Video player of the
Ash File Manager.

see also:
http://code.google.com/p/chromium/issues/detail?id=123739#c17

BUG=138745
TEST=Attach an (Wired USB) Apple keyboard or Windows Natural keyboard
to a Chromebook.
Either download three mp3 and an mp4 file to your chromebook or navigate
to a Google Drive folder that has these.
Bring up File Manager from the Launcher and click on an mp3.
Press the Previous Track, Play/Pause, Next Track keys on the MAC keyboard and
observe same behavior as clicking the corresponding Audio Control buttons
on the screen.
Click on an mp4 and press the Play/Pause key and observe same
behavior as clicking Play/Pause button on the screen.
Repeat for Windows Natural keyboard with the Play/Pause key. (Note
it does not have any prev./next track keys.)
PS: The Goldtouch USB keyboard works as well. The media keys require holding done the "Fn" key and F1, F2, or F3.

Review URL: https://chromiumcodereview.appspot.com/10823439

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153502 0039d316-1c4b-4281-b951-d872f2087c98
parent 79ec9aa6
......@@ -241,6 +241,21 @@ bool HandleMagnifyScreen(int delta_index) {
return true;
}
bool HandleMediaNextTrack() {
Shell::GetInstance()->delegate()->HandleMediaNextTrack();
return true;
}
bool HandleMediaPlayPause() {
Shell::GetInstance()->delegate()->HandleMediaPlayPause();
return true;
}
bool HandleMediaPrevTrack() {
Shell::GetInstance()->delegate()->HandleMediaPrevTrack();
return true;
}
#if !defined(NDEBUG)
bool HandlePrintLayerHierarchy() {
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
......@@ -663,6 +678,12 @@ bool AcceleratorController::PerformAction(int action,
return HandleMagnifyScreen(1);
case MAGNIFY_SCREEN_ZOOM_OUT:
return HandleMagnifyScreen(-1);
case MEDIA_NEXT_TRACK:
return HandleMediaNextTrack();
case MEDIA_PLAY_PAUSE:
return HandleMediaPlayPause();
case MEDIA_PREV_TRACK:
return HandleMediaPrevTrack();
#if !defined(NDEBUG)
case PRINT_LAYER_HIERARCHY:
return HandlePrintLayerHierarchy();
......
......@@ -125,7 +125,12 @@ const AcceleratorData kAcceleratorData[] = {
{ true, ui::VKEY_F2, ui::EF_CONTROL_DOWN, FOCUS_NEXT_PANE },
{ true, ui::VKEY_F1, ui::EF_CONTROL_DOWN, FOCUS_PREVIOUS_PANE },
// TODO(yusukes): Handle VKEY_MEDIA_STOP, VKEY_MEDIA_PLAY_PAUSE, and
// Media Player shortcuts.
{ true, ui::VKEY_MEDIA_NEXT_TRACK, ui::EF_NONE, MEDIA_NEXT_TRACK},
{ true, ui::VKEY_MEDIA_PLAY_PAUSE, ui::EF_NONE, MEDIA_PLAY_PAUSE},
{ true, ui::VKEY_MEDIA_PREV_TRACK, ui::EF_NONE, MEDIA_PREV_TRACK},
// TODO(yusukes): Handle VKEY_MEDIA_STOP, and
// VKEY_MEDIA_LAUNCH_MAIL.
};
......
......@@ -32,6 +32,9 @@ enum AcceleratorAction {
KEYBOARD_BRIGHTNESS_UP,
MAGNIFY_SCREEN_ZOOM_IN,
MAGNIFY_SCREEN_ZOOM_OUT,
MEDIA_NEXT_TRACK,
MEDIA_PLAY_PAUSE,
MEDIA_PREV_TRACK,
NEW_INCOGNITO_WINDOW,
NEW_TAB,
NEW_WINDOW,
......
......@@ -133,5 +133,14 @@ void ShellDelegateImpl::OpenFeedbackPage() {
void ShellDelegateImpl::RecordUserMetricsAction(UserMetricsAction action) {
}
void ShellDelegateImpl::HandleMediaNextTrack() {
}
void ShellDelegateImpl::HandleMediaPlayPause() {
}
void ShellDelegateImpl::HandleMediaPrevTrack() {
}
} // namespace shell
} // namespace ash
......@@ -49,6 +49,9 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;
virtual void HandleMediaNextTrack() OVERRIDE;
virtual void HandleMediaPlayPause() OVERRIDE;
virtual void HandleMediaPrevTrack() OVERRIDE;
private:
// Used to update Launcher. Owned by main.
......
......@@ -137,6 +137,15 @@ class ASH_EXPORT ShellDelegate {
// Records that the user performed an action.
virtual void RecordUserMetricsAction(UserMetricsAction action) = 0;
// Handles the Next Track Media shortcut key.
virtual void HandleMediaNextTrack() = 0;
// Handles the Play/Pause Toggle Media shortcut key.
virtual void HandleMediaPlayPause() = 0;
// Handles the Previous Track Media shortcut key.
virtual void HandleMediaPrevTrack() = 0;
};
} // namespace ash
......
......@@ -118,5 +118,14 @@ void TestShellDelegate::OpenFeedbackPage() {
void TestShellDelegate::RecordUserMetricsAction(UserMetricsAction action) {
}
void TestShellDelegate::HandleMediaNextTrack() {
}
void TestShellDelegate::HandleMediaPlayPause() {
}
void TestShellDelegate::HandleMediaPrevTrack() {
}
} // namespace test
} // namespace ash
......@@ -44,6 +44,9 @@ class TestShellDelegate : public ShellDelegate {
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;
virtual void HandleMediaNextTrack() OVERRIDE;
virtual void HandleMediaPlayPause() OVERRIDE;
virtual void HandleMediaPrevTrack() OVERRIDE;
private:
bool locked_;
......
......@@ -21,10 +21,34 @@ void ExtensionMediaPlayerEventRouter::Init(Profile* profile) {
profile_ = profile;
}
void ExtensionMediaPlayerEventRouter::NotifyNextTrack() {
if (profile_ && profile_->GetExtensionEventRouter()) {
scoped_ptr<ListValue> args(new ListValue());
profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
"mediaPlayerPrivate.onNextTrack", args.Pass(), NULL, GURL());
}
}
void ExtensionMediaPlayerEventRouter::NotifyPlaylistChanged() {
if (profile_ && profile_->GetExtensionEventRouter()) {
scoped_ptr<ListValue> args(new ListValue());
profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
"mediaPlayerPrivate.onPlaylistChanged", args.Pass(), NULL, GURL());
"mediaPlayerPrivate.onPlaylistChanged", args.Pass(), NULL, GURL());
}
}
void ExtensionMediaPlayerEventRouter::NotifyPrevTrack() {
if (profile_ && profile_->GetExtensionEventRouter()) {
scoped_ptr<ListValue> args(new ListValue());
profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
"mediaPlayerPrivate.onPrevTrack", args.Pass(), NULL, GURL());
}
}
void ExtensionMediaPlayerEventRouter::NotifyTogglePlayState() {
if (profile_ && profile_->GetExtensionEventRouter()) {
scoped_ptr<ListValue> args(new ListValue());
profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
"mediaPlayerPrivate.onTogglePlayState", args.Pass(), NULL, GURL());
}
}
......@@ -17,8 +17,18 @@ class ExtensionMediaPlayerEventRouter {
void Init(Profile* profile);
// Send notification that next-track shortcut key was pressed.
void NotifyNextTrack();
// Send notification that playlist changed.
void NotifyPlaylistChanged();
// Send notification that previous-track shortcut key was pressed.
void NotifyPrevTrack();
// Send notification that play/pause shortcut key was pressed.
void NotifyTogglePlayState();
private:
Profile* profile_;
......
......@@ -858,6 +858,10 @@ function VideoControls(containerElement, onMediaError,
'VideoResumePosition',
VideoControls.RESUME_POSITIONS_CAPACITY,
VideoControls.RESUME_POSITION_LIFETIME);
var video_controls = this;
chrome.mediaPlayerPrivate.onTogglePlayState.addListener(
function() { video_controls.togglePlayStateWithFeedback(); });
}
/**
......@@ -1139,6 +1143,14 @@ function AudioControls(container, advanceTrack, onError) {
/* No volume controls */
this.createButton('previous', this.onAdvanceClick_.bind(this, false));
this.createButton('next', this.onAdvanceClick_.bind(this, true));
var audio_controls = this;
chrome.mediaPlayerPrivate.onNextTrack.addListener(
function() { audio_controls.onAdvanceClick_(true); });
chrome.mediaPlayerPrivate.onPrevTrack.addListener(
function() { audio_controls.onAdvanceClick_(false); });
chrome.mediaPlayerPrivate.onTogglePlayState.addListener(
function() { audio_controls.togglePlayState(); });
}
AudioControls.prototype = { __proto__: MediaControls.prototype };
......
......@@ -40,6 +40,7 @@
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_display_host.h"
......@@ -366,6 +367,24 @@ void ChromeShellDelegate::RecordUserMetricsAction(
}
}
void ChromeShellDelegate::HandleMediaNextTrack() {
#if defined(OS_CHROMEOS)
ExtensionMediaPlayerEventRouter::GetInstance()->NotifyNextTrack();
#endif
}
void ChromeShellDelegate::HandleMediaPlayPause() {
#if defined(OS_CHROMEOS)
ExtensionMediaPlayerEventRouter::GetInstance()->NotifyTogglePlayState();
#endif
}
void ChromeShellDelegate::HandleMediaPrevTrack() {
#if defined(OS_CHROMEOS)
ExtensionMediaPlayerEventRouter::GetInstance()->NotifyPrevTrack();
#endif
}
void ChromeShellDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -62,6 +62,9 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(ash::UserMetricsAction action) OVERRIDE;
virtual void HandleMediaNextTrack() OVERRIDE;
virtual void HandleMediaPlayPause() OVERRIDE;
virtual void HandleMediaPrevTrack() OVERRIDE;
// content::NotificationObserver override:
virtual void Observe(int type,
......
......@@ -80,11 +80,29 @@
}
],
"events": [
{
"name": "onNextTrack",
"type": "function",
"description": "Notifies that the next track was requested.",
"parameters": []
},
{
"name": "onPlaylistChanged",
"type": "function",
"description": "Notifies that playlist content or state has been changed. Data could be retrieved via 'getPlaylist'.",
"parameters": []
},
{
"name": "onPrevTrack",
"type": "function",
"description": "Notifies that the previous tack was requested.",
"parameters": []
},
{
"name": "onTogglePlayState",
"type": "function",
"description": "Notifies that a play/pause toggle was requested.",
"parameters": []
}
]
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment