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 29 matching lines...) Expand all Loading... |
40 pending_play_(false), | 40 pending_play_(false), |
41 url_(url), | 41 url_(url), |
42 first_party_for_cookies_(first_party_for_cookies), | 42 first_party_for_cookies_(first_party_for_cookies), |
43 user_agent_(user_agent), | 43 user_agent_(user_agent), |
44 hide_url_log_(hide_url_log), | 44 hide_url_log_(hide_url_log), |
45 width_(0), | 45 width_(0), |
46 height_(0), | 46 height_(0), |
47 can_pause_(true), | 47 can_pause_(true), |
48 can_seek_forward_(true), | 48 can_seek_forward_(true), |
49 can_seek_backward_(true), | 49 can_seek_backward_(true), |
50 is_surface_in_use_(false), | |
51 volume_(-1.0), | 50 volume_(-1.0), |
52 allow_credentials_(allow_credentials), | 51 allow_credentials_(allow_credentials), |
53 weak_factory_(this) { | 52 weak_factory_(this) { |
54 listener_.reset(new MediaPlayerListener(base::MessageLoopProxy::current(), | 53 listener_.reset(new MediaPlayerListener(base::MessageLoopProxy::current(), |
55 weak_factory_.GetWeakPtr())); | 54 weak_factory_.GetWeakPtr())); |
56 } | 55 } |
57 | 56 |
58 MediaPlayerBridge::~MediaPlayerBridge() { | 57 MediaPlayerBridge::~MediaPlayerBridge() { |
59 if (!j_media_player_bridge_.is_null()) { | 58 if (!j_media_player_bridge_.is_null()) { |
60 JNIEnv* env = base::android::AttachCurrentThread(); | 59 JNIEnv* env = base::android::AttachCurrentThread(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 134 |
136 void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) { | 135 void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) { |
137 if (j_media_player_bridge_.is_null()) { | 136 if (j_media_player_bridge_.is_null()) { |
138 if (surface.IsEmpty()) | 137 if (surface.IsEmpty()) |
139 return; | 138 return; |
140 Prepare(); | 139 Prepare(); |
141 } | 140 } |
142 | 141 |
143 JNIEnv* env = base::android::AttachCurrentThread(); | 142 JNIEnv* env = base::android::AttachCurrentThread(); |
144 CHECK(env); | 143 CHECK(env); |
145 is_surface_in_use_ = true; | |
146 Java_MediaPlayerBridge_setSurface( | 144 Java_MediaPlayerBridge_setSurface( |
147 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); | 145 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); |
148 } | 146 } |
149 | 147 |
150 void MediaPlayerBridge::Prepare() { | 148 void MediaPlayerBridge::Prepare() { |
151 DCHECK(j_media_player_bridge_.is_null()); | 149 DCHECK(j_media_player_bridge_.is_null()); |
152 CreateJavaMediaPlayerBridge(); | 150 CreateJavaMediaPlayerBridge(); |
153 if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) { | 151 if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) { |
154 manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( | 152 manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( |
155 url_, | 153 url_, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 375 |
378 void MediaPlayerBridge::Release() { | 376 void MediaPlayerBridge::Release() { |
379 if (j_media_player_bridge_.is_null()) | 377 if (j_media_player_bridge_.is_null()) |
380 return; | 378 return; |
381 | 379 |
382 time_update_timer_.Stop(); | 380 time_update_timer_.Stop(); |
383 if (prepared_) | 381 if (prepared_) |
384 pending_seek_ = GetCurrentTime(); | 382 pending_seek_ = GetCurrentTime(); |
385 prepared_ = false; | 383 prepared_ = false; |
386 pending_play_ = false; | 384 pending_play_ = false; |
387 is_surface_in_use_ = false; | |
388 SetVideoSurface(gfx::ScopedJavaSurface()); | 385 SetVideoSurface(gfx::ScopedJavaSurface()); |
389 JNIEnv* env = base::android::AttachCurrentThread(); | 386 JNIEnv* env = base::android::AttachCurrentThread(); |
390 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); | 387 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); |
391 j_media_player_bridge_.Reset(); | 388 j_media_player_bridge_.Reset(); |
392 listener_->ReleaseMediaPlayerListenerResources(); | 389 listener_->ReleaseMediaPlayerListenerResources(); |
393 } | 390 } |
394 | 391 |
395 void MediaPlayerBridge::SetVolume(double volume) { | 392 void MediaPlayerBridge::SetVolume(double volume) { |
396 if (j_media_player_bridge_.is_null()) { | 393 if (j_media_player_bridge_.is_null()) { |
397 volume_ = volume; | 394 volume_ = volume; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 538 } |
542 | 539 |
543 GURL MediaPlayerBridge::GetUrl() { | 540 GURL MediaPlayerBridge::GetUrl() { |
544 return url_; | 541 return url_; |
545 } | 542 } |
546 | 543 |
547 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 544 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
548 return first_party_for_cookies_; | 545 return first_party_for_cookies_; |
549 } | 546 } |
550 | 547 |
551 bool MediaPlayerBridge::IsSurfaceInUse() const { | |
552 return is_surface_in_use_; | |
553 } | |
554 | |
555 } // namespace media | 548 } // namespace media |
OLD | NEW |