OLD | NEW |
---|---|
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 "media/base/android/media_player_bridge.h" | 5 #include "media/base/android/media_player_bridge.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 resource_getter->GetCookies(url_, first_party_for_cookies_, base::Bind( | 67 resource_getter->GetCookies(url_, first_party_for_cookies_, base::Bind( |
68 &MediaPlayerBridge::OnCookiesRetrieved, weak_this_.GetWeakPtr())); | 68 &MediaPlayerBridge::OnCookiesRetrieved, weak_this_.GetWeakPtr())); |
69 } | 69 } |
70 | 70 |
71 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { | 71 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { |
72 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
73 CHECK(env); | 73 CHECK(env); |
74 | 74 |
75 j_media_player_bridge_.Reset(Java_MediaPlayerBridge_create(env)); | 75 j_media_player_bridge_.Reset(Java_MediaPlayerBridge_create(env)); |
76 | 76 |
77 if (!surface_.IsEmpty()) { | |
78 JNIEnv* env = base::android::AttachCurrentThread(); | |
qinmin
2013/11/22 18:06:55
env is already defined inside this function.
| |
79 CHECK(env); | |
80 Java_MediaPlayerBridge_setSurface( | |
81 env, j_media_player_bridge_.obj(), surface_.j_surface().obj()); | |
82 } | |
83 | |
77 SetMediaPlayerListener(); | 84 SetMediaPlayerListener(); |
78 } | 85 } |
79 | 86 |
80 void MediaPlayerBridge::SetJavaMediaPlayerBridge( | 87 void MediaPlayerBridge::SetJavaMediaPlayerBridge( |
81 jobject j_media_player_bridge) { | 88 jobject j_media_player_bridge) { |
82 JNIEnv* env = base::android::AttachCurrentThread(); | 89 JNIEnv* env = base::android::AttachCurrentThread(); |
83 CHECK(env); | 90 CHECK(env); |
84 | 91 |
85 j_media_player_bridge_.Reset(env, j_media_player_bridge); | 92 j_media_player_bridge_.Reset(env, j_media_player_bridge); |
86 } | 93 } |
(...skipping 16 matching lines...) Expand all Loading... | |
103 duration_ = duration; | 110 duration_ = duration; |
104 } | 111 } |
105 | 112 |
106 void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) { | 113 void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) { |
107 if (j_media_player_bridge_.is_null()) { | 114 if (j_media_player_bridge_.is_null()) { |
108 if (surface.IsEmpty()) | 115 if (surface.IsEmpty()) |
109 return; | 116 return; |
110 Prepare(); | 117 Prepare(); |
111 } | 118 } |
112 | 119 |
120 surface_ = surface.Pass(); | |
121 | |
113 JNIEnv* env = base::android::AttachCurrentThread(); | 122 JNIEnv* env = base::android::AttachCurrentThread(); |
114 CHECK(env); | 123 CHECK(env); |
115 | 124 |
116 Java_MediaPlayerBridge_setSurface( | 125 Java_MediaPlayerBridge_setSurface( |
117 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); | 126 env, j_media_player_bridge_.obj(), surface_.j_surface().obj()); |
118 } | 127 } |
119 | 128 |
120 void MediaPlayerBridge::Prepare() { | 129 void MediaPlayerBridge::Prepare() { |
121 DCHECK(j_media_player_bridge_.is_null()); | 130 DCHECK(j_media_player_bridge_.is_null()); |
122 CreateJavaMediaPlayerBridge(); | 131 CreateJavaMediaPlayerBridge(); |
123 if (url_.SchemeIsFileSystem()) { | 132 if (url_.SchemeIsFileSystem()) { |
124 manager()->GetMediaResourceGetter()->GetPlatformPathFromFileSystemURL( | 133 manager()->GetMediaResourceGetter()->GetPlatformPathFromFileSystemURL( |
125 url_, base::Bind(&MediaPlayerBridge::SetDataSource, | 134 url_, base::Bind(&MediaPlayerBridge::SetDataSource, |
126 weak_this_.GetWeakPtr())); | 135 weak_this_.GetWeakPtr())); |
127 } else { | 136 } else { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 | 267 |
259 void MediaPlayerBridge::Release() { | 268 void MediaPlayerBridge::Release() { |
260 if (j_media_player_bridge_.is_null()) | 269 if (j_media_player_bridge_.is_null()) |
261 return; | 270 return; |
262 | 271 |
263 time_update_timer_.Stop(); | 272 time_update_timer_.Stop(); |
264 if (prepared_) | 273 if (prepared_) |
265 pending_seek_ = GetCurrentTime(); | 274 pending_seek_ = GetCurrentTime(); |
266 prepared_ = false; | 275 prepared_ = false; |
267 pending_play_ = false; | 276 pending_play_ = false; |
268 SetVideoSurface(gfx::ScopedJavaSurface()); | |
269 | 277 |
278 // Detach the surface from the java side player. We still hold our reference | |
279 // to it because we might reuse it when restarting with a new player. | |
270 JNIEnv* env = base::android::AttachCurrentThread(); | 280 JNIEnv* env = base::android::AttachCurrentThread(); |
281 Java_MediaPlayerBridge_setSurface(env, j_media_player_bridge_.obj(), NULL); | |
282 | |
271 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); | 283 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); |
272 j_media_player_bridge_.Reset(); | 284 j_media_player_bridge_.Reset(); |
273 manager()->ReleaseMediaResources(player_id()); | 285 manager()->ReleaseMediaResources(player_id()); |
274 listener_.ReleaseMediaPlayerListenerResources(); | 286 listener_.ReleaseMediaPlayerListenerResources(); |
275 } | 287 } |
276 | 288 |
277 void MediaPlayerBridge::SetVolume(double volume) { | 289 void MediaPlayerBridge::SetVolume(double volume) { |
278 if (j_media_player_bridge_.is_null()) | 290 if (j_media_player_bridge_.is_null()) |
279 return; | 291 return; |
280 | 292 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 | 433 |
422 GURL MediaPlayerBridge::GetUrl() { | 434 GURL MediaPlayerBridge::GetUrl() { |
423 return url_; | 435 return url_; |
424 } | 436 } |
425 | 437 |
426 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 438 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
427 return first_party_for_cookies_; | 439 return first_party_for_cookies_; |
428 } | 440 } |
429 | 441 |
430 } // namespace media | 442 } // namespace media |
OLD | NEW |