OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/media/android/browser_media_player_manager.h" | 5 #include "content/browser/media/android/browser_media_player_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/android/content_view_core_impl.h" | 8 #include "content/browser/android/content_view_core_impl.h" |
9 #include "content/browser/media/android/browser_demuxer_android.h" | 9 #include "content/browser/media/android/browser_demuxer_android.h" |
10 #include "content/browser/media/android/media_resource_getter_impl.h" | 10 #include "content/browser/media/android/media_resource_getter_impl.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 NOTREACHED(); | 85 NOTREACHED(); |
86 return NULL; | 86 return NULL; |
87 } | 87 } |
88 #endif | 88 #endif |
89 | 89 |
90 BrowserMediaPlayerManager::BrowserMediaPlayerManager( | 90 BrowserMediaPlayerManager::BrowserMediaPlayerManager( |
91 RenderViewHost* render_view_host) | 91 RenderViewHost* render_view_host) |
92 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), | 92 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), |
93 fullscreen_player_id_(-1), | 93 fullscreen_player_id_(-1), |
94 pending_fullscreen_player_id_(-1), | 94 pending_fullscreen_player_id_(-1), |
| 95 fullscreen_player_is_released_(false), |
95 web_contents_(WebContents::FromRenderViewHost(render_view_host)), | 96 web_contents_(WebContents::FromRenderViewHost(render_view_host)), |
96 weak_ptr_factory_(this) { | 97 weak_ptr_factory_(this) { |
97 } | 98 } |
98 | 99 |
99 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} | 100 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} |
100 | 101 |
101 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { | 102 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { |
102 bool handled = true; | 103 bool handled = true; |
103 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) | 104 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) |
104 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) | 105 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) |
(...skipping 19 matching lines...) Expand all Loading... |
124 OnNotifyExternalSurface) | 125 OnNotifyExternalSurface) |
125 #endif | 126 #endif |
126 IPC_MESSAGE_UNHANDLED(handled = false) | 127 IPC_MESSAGE_UNHANDLED(handled = false) |
127 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
128 return handled; | 129 return handled; |
129 } | 130 } |
130 | 131 |
131 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 132 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
132 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 133 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
133 if (player) { | 134 if (player) { |
| 135 if (fullscreen_player_is_released_) { |
| 136 video_view_->OpenVideo(); |
| 137 fullscreen_player_is_released_ = false; |
| 138 } |
134 player->Start(); | 139 player->Start(); |
135 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 140 Send(new MediaPlayerMsg_DidMediaPlayerPlay( |
136 routing_id(), fullscreen_player_id_)); | 141 routing_id(), fullscreen_player_id_)); |
137 } | 142 } |
138 } | 143 } |
139 | 144 |
140 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 145 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
141 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 146 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
142 if (player) { | 147 if (player) { |
143 player->Pause(true); | 148 player->Pause(true); |
144 Send(new MediaPlayerMsg_DidMediaPlayerPause( | 149 Send(new MediaPlayerMsg_DidMediaPlayerPause( |
145 routing_id(), fullscreen_player_id_)); | 150 routing_id(), fullscreen_player_id_)); |
146 } | 151 } |
147 } | 152 } |
148 | 153 |
149 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { | 154 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { |
150 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 155 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
151 if (player) { | 156 if (player) { |
| 157 // TODO(kbalazs): if |fullscreen_player_is_released_| is true |
| 158 // at this point, player->GetCurrentTime() will be wrong until |
| 159 // FullscreenPlayerPlay (http://crbug.com/322798). |
152 OnSeekRequest(fullscreen_player_id_, | 160 OnSeekRequest(fullscreen_player_id_, |
153 base::TimeDelta::FromMilliseconds(msec)); | 161 base::TimeDelta::FromMilliseconds(msec)); |
154 } | 162 } |
155 } | 163 } |
156 | 164 |
157 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { | 165 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { |
158 Send(new MediaPlayerMsg_DidExitFullscreen( | 166 Send(new MediaPlayerMsg_DidExitFullscreen( |
159 routing_id(), fullscreen_player_id_)); | 167 routing_id(), fullscreen_player_id_)); |
160 video_view_.reset(); | 168 video_view_.reset(); |
161 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 169 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 500 } |
493 | 501 |
494 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { | 502 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { |
495 MediaPlayerAndroid* player = GetPlayer(player_id); | 503 MediaPlayerAndroid* player = GetPlayer(player_id); |
496 if (player) | 504 if (player) |
497 player->SetVolume(volume); | 505 player->SetVolume(volume); |
498 } | 506 } |
499 | 507 |
500 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 508 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
501 MediaPlayerAndroid* player = GetPlayer(player_id); | 509 MediaPlayerAndroid* player = GetPlayer(player_id); |
502 // Don't release the fullscreen player when tab visibility changes, | 510 if (player) |
503 // it will be released when user hit the back/home button or when | |
504 // OnDestroyPlayer is called. | |
505 if (player && player_id != fullscreen_player_id_) | |
506 player->Release(); | 511 player->Release(); |
| 512 if (player_id == fullscreen_player_id_) |
| 513 fullscreen_player_is_released_ = true; |
507 | 514 |
508 #if defined(GOOGLE_TV) | 515 #if defined(GOOGLE_TV) |
509 WebContentsViewAndroid* view = | 516 WebContentsViewAndroid* view = |
510 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 517 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); |
511 if (view) | 518 if (view) |
512 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | 519 view->NotifyExternalSurface(player_id, false, gfx::RectF()); |
513 #endif | 520 #endif |
514 } | 521 } |
515 | 522 |
516 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 523 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 if (pending_fullscreen_player_id_ != media_keys_id) | 721 if (pending_fullscreen_player_id_ != media_keys_id) |
715 return; | 722 return; |
716 | 723 |
717 pending_fullscreen_player_id_ = -1; | 724 pending_fullscreen_player_id_ = -1; |
718 MediaPlayerAndroid* player = GetPlayer(media_keys_id); | 725 MediaPlayerAndroid* player = GetPlayer(media_keys_id); |
719 if (player->IsPlaying()) | 726 if (player->IsPlaying()) |
720 OnProtectedSurfaceRequested(media_keys_id); | 727 OnProtectedSurfaceRequested(media_keys_id); |
721 } | 728 } |
722 | 729 |
723 } // namespace content | 730 } // namespace content |
OLD | NEW |