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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 OnNotifyExternalSurface) | 133 OnNotifyExternalSurface) |
134 #endif | 134 #endif |
135 IPC_MESSAGE_UNHANDLED(handled = false) | 135 IPC_MESSAGE_UNHANDLED(handled = false) |
136 IPC_END_MESSAGE_MAP() | 136 IPC_END_MESSAGE_MAP() |
137 return handled; | 137 return handled; |
138 } | 138 } |
139 | 139 |
140 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 140 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
141 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 141 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
142 if (player) { | 142 if (player) { |
143 if (fullscreen_player_is_released_) { | |
144 video_view_->OpenVideo(); | |
145 fullscreen_player_is_released_ = false; | |
146 } | |
147 player->Start(); | 143 player->Start(); |
148 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 144 Send(new MediaPlayerMsg_DidMediaPlayerPlay( |
149 routing_id(), fullscreen_player_id_)); | 145 routing_id(), fullscreen_player_id_)); |
150 } | 146 } |
151 } | 147 } |
152 | 148 |
153 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 149 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
154 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 150 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
155 if (player) { | 151 if (player) { |
156 player->Pause(true); | 152 player->Pause(true); |
157 Send(new MediaPlayerMsg_DidMediaPlayerPause( | 153 Send(new MediaPlayerMsg_DidMediaPlayerPause( |
158 routing_id(), fullscreen_player_id_)); | 154 routing_id(), fullscreen_player_id_)); |
159 } | 155 } |
160 } | 156 } |
161 | 157 |
162 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { | 158 void BrowserMediaPlayerManager::FullscreenPlayerSeek(int msec) { |
163 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 159 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
164 if (player) { | 160 if (player) { |
165 // TODO(kbalazs): if |fullscreen_player_is_released_| is true | 161 // TODO(kbalazs): if the fullscreen player has been Release()-d and |
166 // at this point, player->GetCurrentTime() will be wrong until | 162 // not restarted yet, player->GetCurrentTime() will be wrong until |
167 // FullscreenPlayerPlay (http://crbug.com/322798). | 163 // FullscreenPlayerPlay (http://crbug.com/322798). |
168 OnSeekRequest(fullscreen_player_id_, | 164 OnSeekRequest(fullscreen_player_id_, |
169 base::TimeDelta::FromMilliseconds(msec)); | 165 base::TimeDelta::FromMilliseconds(msec)); |
170 } | 166 } |
171 } | 167 } |
172 | 168 |
173 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { | 169 void BrowserMediaPlayerManager::ExitFullscreen(bool release_media_player) { |
174 Send(new MediaPlayerMsg_DidExitFullscreen( | 170 Send(new MediaPlayerMsg_DidExitFullscreen( |
175 routing_id(), fullscreen_player_id_)); | 171 routing_id(), fullscreen_player_id_)); |
176 video_view_.reset(); | 172 video_view_.reset(); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 OnExitFullscreen(fullscreen_player_id_); | 439 OnExitFullscreen(fullscreen_player_id_); |
444 } | 440 } |
445 | 441 |
446 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { | 442 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { |
447 DCHECK_EQ(fullscreen_player_id_, -1); | 443 DCHECK_EQ(fullscreen_player_id_, -1); |
448 if (media_keys_ids_pending_approval_.find(player_id) != | 444 if (media_keys_ids_pending_approval_.find(player_id) != |
449 media_keys_ids_pending_approval_.end()) { | 445 media_keys_ids_pending_approval_.end()) { |
450 return; | 446 return; |
451 } | 447 } |
452 | 448 |
453 if (video_view_.get()) { | 449 if (!ContentVideoView::HasContentVideoView()) { |
454 fullscreen_player_id_ = player_id; | |
455 video_view_->OpenVideo(); | |
456 } else if (!ContentVideoView::HasContentVideoView()) { | |
457 // In Android WebView, two ContentViewCores could both try to enter | 450 // In Android WebView, two ContentViewCores could both try to enter |
458 // fullscreen video, we just ignore the second one. | 451 // fullscreen video, we just ignore the second one. |
459 fullscreen_player_id_ = player_id; | 452 fullscreen_player_id_ = player_id; |
460 ContentViewCoreImpl* content_view_core_impl = | 453 ContentViewCoreImpl* content_view_core_impl = |
461 ContentViewCoreImpl::FromWebContents(web_contents()); | 454 ContentViewCoreImpl::FromWebContents(web_contents()); |
462 video_view_.reset(new ContentVideoView(content_view_core_impl->GetContext(), | 455 video_view_.reset(new ContentVideoView(content_view_core_impl->GetContext(), |
463 content_view_core_impl->GetContentVideoViewClient(), this)); | 456 content_view_core_impl->GetContentVideoViewClient(), this)); |
464 } | 457 } |
465 } | 458 } |
466 | 459 |
467 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { | 460 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { |
468 if (fullscreen_player_id_ == player_id) { | 461 if (fullscreen_player_id_ == player_id) { |
469 MediaPlayerAndroid* player = GetPlayer(player_id); | 462 MediaPlayerAndroid* player = GetPlayer(player_id); |
470 if (player) | 463 if (player) |
471 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 464 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
472 video_view_->OnExitFullscreen(); | 465 video_view_.reset(); |
| 466 fullscreen_player_id_ = -1; |
473 } | 467 } |
474 } | 468 } |
475 | 469 |
476 void BrowserMediaPlayerManager::OnInitialize( | 470 void BrowserMediaPlayerManager::OnInitialize( |
477 MediaPlayerHostMsg_Initialize_Type type, | 471 MediaPlayerHostMsg_Initialize_Type type, |
478 int player_id, | 472 int player_id, |
479 const GURL& url, | 473 const GURL& url, |
480 const GURL& first_party_for_cookies, | 474 const GURL& first_party_for_cookies, |
481 int demuxer_client_id) { | 475 int demuxer_client_id) { |
482 DCHECK(type != MEDIA_PLAYER_TYPE_MEDIA_SOURCE || demuxer_client_id > 0) | 476 DCHECK(type != MEDIA_PLAYER_TYPE_MEDIA_SOURCE || demuxer_client_id > 0) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { | 512 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { |
519 MediaPlayerAndroid* player = GetPlayer(player_id); | 513 MediaPlayerAndroid* player = GetPlayer(player_id); |
520 if (player) | 514 if (player) |
521 player->SetVolume(volume); | 515 player->SetVolume(volume); |
522 } | 516 } |
523 | 517 |
524 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 518 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
525 MediaPlayerAndroid* player = GetPlayer(player_id); | 519 MediaPlayerAndroid* player = GetPlayer(player_id); |
526 if (player) | 520 if (player) |
527 player->Release(); | 521 player->Release(); |
528 if (player_id == fullscreen_player_id_) | |
529 fullscreen_player_is_released_ = true; | |
530 | 522 |
531 #if defined(GOOGLE_TV) | 523 #if defined(GOOGLE_TV) |
532 WebContentsViewAndroid* view = | 524 WebContentsViewAndroid* view = |
533 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 525 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); |
534 if (view) | 526 if (view) |
535 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | 527 view->NotifyExternalSurface(player_id, false, gfx::RectF()); |
536 #endif | 528 #endif |
537 } | 529 } |
538 | 530 |
539 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 531 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 if (pending_fullscreen_player_id_ != media_keys_id) | 732 if (pending_fullscreen_player_id_ != media_keys_id) |
741 return; | 733 return; |
742 | 734 |
743 pending_fullscreen_player_id_ = -1; | 735 pending_fullscreen_player_id_ = -1; |
744 MediaPlayerAndroid* player = GetPlayer(media_keys_id); | 736 MediaPlayerAndroid* player = GetPlayer(media_keys_id); |
745 if (player->IsPlaying()) | 737 if (player->IsPlaying()) |
746 OnProtectedSurfaceRequested(media_keys_id); | 738 OnProtectedSurfaceRequested(media_keys_id); |
747 } | 739 } |
748 | 740 |
749 } // namespace content | 741 } // namespace content |
OLD | NEW |