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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 url_(url), | 43 url_(url), |
44 first_party_for_cookies_(first_party_for_cookies), | 44 first_party_for_cookies_(first_party_for_cookies), |
45 user_agent_(user_agent), | 45 user_agent_(user_agent), |
46 hide_url_log_(hide_url_log), | 46 hide_url_log_(hide_url_log), |
47 width_(0), | 47 width_(0), |
48 height_(0), | 48 height_(0), |
49 can_pause_(true), | 49 can_pause_(true), |
50 can_seek_forward_(true), | 50 can_seek_forward_(true), |
51 can_seek_backward_(true), | 51 can_seek_backward_(true), |
52 is_surface_in_use_(false), | 52 is_surface_in_use_(false), |
| 53 volume_(-1.0), |
53 weak_factory_(this) { | 54 weak_factory_(this) { |
54 listener_.reset(new MediaPlayerListener(base::MessageLoopProxy::current(), | 55 listener_.reset(new MediaPlayerListener(base::MessageLoopProxy::current(), |
55 weak_factory_.GetWeakPtr())); | 56 weak_factory_.GetWeakPtr())); |
56 } | 57 } |
57 | 58 |
58 MediaPlayerBridge::~MediaPlayerBridge() { | 59 MediaPlayerBridge::~MediaPlayerBridge() { |
59 if (!j_media_player_bridge_.is_null()) { | 60 if (!j_media_player_bridge_.is_null()) { |
60 JNIEnv* env = base::android::AttachCurrentThread(); | 61 JNIEnv* env = base::android::AttachCurrentThread(); |
61 CHECK(env); | 62 CHECK(env); |
62 Java_MediaPlayerBridge_destroy(env, j_media_player_bridge_.obj()); | 63 Java_MediaPlayerBridge_destroy(env, j_media_player_bridge_.obj()); |
(...skipping 24 matching lines...) Expand all Loading... |
87 weak_factory_.GetWeakPtr())); | 88 weak_factory_.GetWeakPtr())); |
88 } | 89 } |
89 | 90 |
90 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { | 91 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { |
91 JNIEnv* env = base::android::AttachCurrentThread(); | 92 JNIEnv* env = base::android::AttachCurrentThread(); |
92 CHECK(env); | 93 CHECK(env); |
93 | 94 |
94 j_media_player_bridge_.Reset(Java_MediaPlayerBridge_create( | 95 j_media_player_bridge_.Reset(Java_MediaPlayerBridge_create( |
95 env, reinterpret_cast<intptr_t>(this))); | 96 env, reinterpret_cast<intptr_t>(this))); |
96 | 97 |
| 98 if (volume_ >= 0) |
| 99 SetVolume(volume_); |
| 100 |
97 SetMediaPlayerListener(); | 101 SetMediaPlayerListener(); |
98 } | 102 } |
99 | 103 |
100 void MediaPlayerBridge::SetJavaMediaPlayerBridge( | 104 void MediaPlayerBridge::SetJavaMediaPlayerBridge( |
101 jobject j_media_player_bridge) { | 105 jobject j_media_player_bridge) { |
102 JNIEnv* env = base::android::AttachCurrentThread(); | 106 JNIEnv* env = base::android::AttachCurrentThread(); |
103 CHECK(env); | 107 CHECK(env); |
104 | 108 |
105 j_media_player_bridge_.Reset(env, j_media_player_bridge); | 109 j_media_player_bridge_.Reset(env, j_media_player_bridge); |
106 } | 110 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 is_surface_in_use_ = false; | 320 is_surface_in_use_ = false; |
317 SetVideoSurface(gfx::ScopedJavaSurface()); | 321 SetVideoSurface(gfx::ScopedJavaSurface()); |
318 JNIEnv* env = base::android::AttachCurrentThread(); | 322 JNIEnv* env = base::android::AttachCurrentThread(); |
319 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); | 323 Java_MediaPlayerBridge_release(env, j_media_player_bridge_.obj()); |
320 j_media_player_bridge_.Reset(); | 324 j_media_player_bridge_.Reset(); |
321 release_media_resources_cb_.Run(player_id()); | 325 release_media_resources_cb_.Run(player_id()); |
322 listener_->ReleaseMediaPlayerListenerResources(); | 326 listener_->ReleaseMediaPlayerListenerResources(); |
323 } | 327 } |
324 | 328 |
325 void MediaPlayerBridge::SetVolume(double volume) { | 329 void MediaPlayerBridge::SetVolume(double volume) { |
326 if (j_media_player_bridge_.is_null()) | 330 if (j_media_player_bridge_.is_null()) { |
| 331 volume_ = volume; |
327 return; | 332 return; |
| 333 } |
328 | 334 |
329 JNIEnv* env = base::android::AttachCurrentThread(); | 335 JNIEnv* env = base::android::AttachCurrentThread(); |
330 CHECK(env); | 336 CHECK(env); |
331 Java_MediaPlayerBridge_setVolume( | 337 Java_MediaPlayerBridge_setVolume( |
332 env, j_media_player_bridge_.obj(), volume); | 338 env, j_media_player_bridge_.obj(), volume); |
333 } | 339 } |
334 | 340 |
335 void MediaPlayerBridge::OnVideoSizeChanged(int width, int height) { | 341 void MediaPlayerBridge::OnVideoSizeChanged(int width, int height) { |
336 width_ = width; | 342 width_ = width; |
337 height_ = height; | 343 height_ = height; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 479 |
474 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 480 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
475 return first_party_for_cookies_; | 481 return first_party_for_cookies_; |
476 } | 482 } |
477 | 483 |
478 bool MediaPlayerBridge::IsSurfaceInUse() const { | 484 bool MediaPlayerBridge::IsSurfaceInUse() const { |
479 return is_surface_in_use_; | 485 return is_surface_in_use_; |
480 } | 486 } |
481 | 487 |
482 } // namespace media | 488 } // namespace media |
OLD | NEW |