Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: content/browser/android/content_video_view.cc

Issue 103583005: Restart fullscreen video playback when switching back from background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle everything at browser side Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/android/content_video_view.h" 5 #include "content/browser/android/content_video_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/android/content_view_core_impl.h"
9 #include "content/browser/media/android/browser_media_player_manager.h" 10 #include "content/browser/media/android/browser_media_player_manager.h"
10 #include "content/common/android/surface_texture_peer.h" 11 #include "content/common/android/surface_texture_peer.h"
11 #include "content/public/common/content_switches.h" 12 #include "content/public/common/content_switches.h"
12 #include "jni/ContentVideoView_jni.h" 13 #include "jni/ContentVideoView_jni.h"
13 14
14 using base::android::AttachCurrentThread; 15 using base::android::AttachCurrentThread;
15 using base::android::CheckException; 16 using base::android::CheckException;
16 using base::android::ScopedJavaGlobalRef; 17 using base::android::ScopedJavaGlobalRef;
17 18
18 namespace content { 19 namespace content {
19 20
20 namespace { 21 namespace {
21 // There can only be one content video view at a time, this holds onto that 22 // There can only be one content video view at a time, this holds onto that
22 // singleton instance. 23 // singleton instance.
23 ContentVideoView* g_content_video_view = NULL; 24 ContentVideoView* g_content_video_view = NULL;
24 25
25 } // namespace 26 } // namespace
26 27
27 static jobject GetSingletonJavaContentVideoView(JNIEnv*env, jclass) { 28 static jobject GetSingletonJavaContentVideoView(JNIEnv*env, jclass) {
28 if (g_content_video_view) 29 if (g_content_video_view)
29 return g_content_video_view->GetJavaObject(env).Release(); 30 return g_content_video_view->GetJavaObject(env).Release();
30 else 31 else
31 return NULL; 32 return NULL;
32 } 33 }
33 34
34 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { 35 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) {
35 return RegisterNativesImpl(env); 36 return RegisterNativesImpl(env);
36 } 37 }
37 38
38 bool ContentVideoView::HasContentVideoView() { 39 ContentVideoView* ContentVideoView::GetInstance() {
39 return g_content_video_view; 40 return g_content_video_view;
40 } 41 }
41 42
42 ContentVideoView::ContentVideoView( 43 ContentVideoView::ContentVideoView(
43 const ScopedJavaLocalRef<jobject>& context,
44 const ScopedJavaLocalRef<jobject>& client,
45 BrowserMediaPlayerManager* manager) 44 BrowserMediaPlayerManager* manager)
46 : manager_(manager) { 45 : manager_(manager),
46 fullscreen_state_(Entered) {
47 DCHECK(!g_content_video_view); 47 DCHECK(!g_content_video_view);
48 JNIEnv *env = AttachCurrentThread(); 48 ContentViewCoreImpl* content_view = manager_->GetContentViewCore();
49 j_content_video_view_ = JavaObjectWeakGlobalRef(env, 49 j_content_video_view_ = CreateJavaObject(content_view);
50 Java_ContentVideoView_createContentVideoView(env, context.obj(),
51 reinterpret_cast<intptr_t>(this), client.obj()).obj());
52 g_content_video_view = this; 50 g_content_video_view = this;
53 } 51 }
54 52
55 ContentVideoView::~ContentVideoView() { 53 ContentVideoView::~ContentVideoView() {
56 DCHECK(g_content_video_view); 54 DCHECK(g_content_video_view);
57 DestroyContentVideoView(true); 55 DestroyContentVideoView(true);
58 g_content_video_view = NULL; 56 g_content_video_view = NULL;
59 } 57 }
60 58
61 void ContentVideoView::OpenVideo() { 59 void ContentVideoView::OpenVideo() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 139
142 void ContentVideoView::Play(JNIEnv*, jobject obj) { 140 void ContentVideoView::Play(JNIEnv*, jobject obj) {
143 manager_->FullscreenPlayerPlay(); 141 manager_->FullscreenPlayerPlay();
144 } 142 }
145 143
146 void ContentVideoView::Pause(JNIEnv*, jobject obj) { 144 void ContentVideoView::Pause(JNIEnv*, jobject obj) {
147 manager_->FullscreenPlayerPause(); 145 manager_->FullscreenPlayerPause();
148 } 146 }
149 147
150 void ContentVideoView::ExitFullscreen( 148 void ContentVideoView::ExitFullscreen(
151 JNIEnv*, jobject, jboolean release_media_player) { 149 JNIEnv* env, jobject, jboolean release_media_player) {
150 DCHECK(fullscreen_state_ == Entered);
152 j_content_video_view_.reset(); 151 j_content_video_view_.reset();
153 manager_->ExitFullscreen(release_media_player); 152 manager_->ExitFullscreen(release_media_player);
154 } 153 }
155 154
155 void ContentVideoView::SuspendFullscreen() {
156 if (fullscreen_state_ != Entered)
157 return;
158 fullscreen_state_ = Suspend;
159 DestroyContentVideoView(false);
160 manager_->SuspendFullscreen();
161 }
162
163 void ContentVideoView::ResumeFullscreenIfSuspended() {
164 if (fullscreen_state_ != Suspend)
165 return;
166 JNIEnv* env = AttachCurrentThread();
167 DCHECK(!GetJavaObject(env).obj());
168 fullscreen_state_ = Resume;
169 j_content_video_view_ = CreateJavaObject(manager_->GetContentViewCore());
170 }
171
156 void ContentVideoView::SetSurface(JNIEnv* env, jobject obj, 172 void ContentVideoView::SetSurface(JNIEnv* env, jobject obj,
157 jobject surface) { 173 jobject surface) {
158 manager_->SetVideoSurface( 174 gfx::ScopedJavaSurface scoped_surface =
159 gfx::ScopedJavaSurface::AcquireExternalSurface(surface)); 175 gfx::ScopedJavaSurface::AcquireExternalSurface(surface);
176 if (fullscreen_state_ == Resume)
177 manager_->ResumeFullscreen(scoped_surface.Pass());
178 else
179 manager_->SetVideoSurface(scoped_surface.Pass());
180 fullscreen_state_ = Entered;
160 } 181 }
161 182
162 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { 183 void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) {
163 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); 184 media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer();
164 if (player && player->IsPlayerReady()) 185 if (player && player->IsPlayerReady())
165 Java_ContentVideoView_onUpdateMediaMetadata( 186 Java_ContentVideoView_onUpdateMediaMetadata(
166 env, obj, player->GetVideoWidth(), player->GetVideoHeight(), 187 env, obj, player->GetVideoWidth(), player->GetVideoHeight(),
167 player->GetDuration().InMilliseconds(), player->CanPause(), 188 player->GetDuration().InMilliseconds(), player->CanPause(),
168 player->CanSeekForward(), player->CanSeekBackward()); 189 player->CanSeekForward(), player->CanSeekBackward());
169 } 190 }
170 191
171 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { 192 ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) {
172 return j_content_video_view_.get(env); 193 return j_content_video_view_.get(env);
173 } 194 }
174 195
196 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject(
197 ContentViewCoreImpl* content_view_core) {
198 JNIEnv *env = AttachCurrentThread();
199 return JavaObjectWeakGlobalRef(env,
200 Java_ContentVideoView_createContentVideoView(env,
qinmin 2013/12/18 02:09:46 nit:fix the indentation
201 content_view_core->GetContext().obj(),
202 reinterpret_cast<intptr_t>(this),
203 content_view_core->GetContentVideoViewClient().obj()).obj());
204 }
205
175 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) { 206 void ContentVideoView::DestroyContentVideoView(bool native_view_destroyed) {
176 JNIEnv *env = AttachCurrentThread(); 207 JNIEnv *env = AttachCurrentThread();
177 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); 208 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
178 if (!content_video_view.is_null()) { 209 if (!content_video_view.is_null()) {
179 Java_ContentVideoView_destroyContentVideoView(env, 210 Java_ContentVideoView_destroyContentVideoView(env,
180 content_video_view.obj(), native_view_destroyed); 211 content_video_view.obj(), native_view_destroyed);
181 j_content_video_view_.reset(); 212 j_content_video_view_.reset();
182 } 213 }
183 } 214 }
184 } // namespace content 215 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698