| 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" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "jni/MediaPlayerBridge_jni.h" | 13 #include "jni/MediaPlayerBridge_jni.h" |
| 14 #include "media/base/android/media_player_manager.h" | 14 #include "media/base/android/media_player_manager.h" |
| 15 #include "media/base/android/media_resource_getter.h" | 15 #include "media/base/android/media_resource_getter.h" |
| 16 | 16 |
| 17 using base::android::ConvertUTF8ToJavaString; | 17 using base::android::ConvertUTF8ToJavaString; |
| 18 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
| 19 | 19 |
| 20 // Time update happens every 250ms. | 20 // Time update happens every 250ms. |
| 21 static const int kTimeUpdateInterval = 250; | 21 static const int kTimeUpdateInterval = 250; |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 MediaPlayerBridge::MediaPlayerBridge( | 25 MediaPlayerBridge::MediaPlayerBridge( |
| 26 int player_id, | 26 int player_id, |
| 27 const GURL& url, | 27 const GURL& url, |
| 28 const GURL& first_party_for_cookies, | 28 const GURL& first_party_for_cookies, |
| 29 const std::string& user_agent, |
| 29 bool hide_url_log, | 30 bool hide_url_log, |
| 30 MediaPlayerManager* manager) | 31 MediaPlayerManager* manager) |
| 31 : MediaPlayerAndroid(player_id, | 32 : MediaPlayerAndroid(player_id, |
| 32 manager), | 33 manager), |
| 33 prepared_(false), | 34 prepared_(false), |
| 34 pending_play_(false), | 35 pending_play_(false), |
| 35 url_(url), | 36 url_(url), |
| 36 first_party_for_cookies_(first_party_for_cookies), | 37 first_party_for_cookies_(first_party_for_cookies), |
| 38 user_agent_(user_agent), |
| 37 hide_url_log_(hide_url_log), | 39 hide_url_log_(hide_url_log), |
| 38 width_(0), | 40 width_(0), |
| 39 height_(0), | 41 height_(0), |
| 40 can_pause_(true), | 42 can_pause_(true), |
| 41 can_seek_forward_(true), | 43 can_seek_forward_(true), |
| 42 can_seek_backward_(true), | 44 can_seek_backward_(true), |
| 43 weak_this_(this), | 45 weak_this_(this), |
| 44 listener_(base::MessageLoopProxy::current(), | 46 listener_(base::MessageLoopProxy::current(), |
| 45 weak_this_.GetWeakPtr()) { | 47 weak_this_.GetWeakPtr()) { |
| 46 } | 48 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (j_media_player_bridge_.is_null()) | 142 if (j_media_player_bridge_.is_null()) |
| 141 return; | 143 return; |
| 142 | 144 |
| 143 JNIEnv* env = base::android::AttachCurrentThread(); | 145 JNIEnv* env = base::android::AttachCurrentThread(); |
| 144 CHECK(env); | 146 CHECK(env); |
| 145 | 147 |
| 146 // Create a Java String for the URL. | 148 // Create a Java String for the URL. |
| 147 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); | 149 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); |
| 148 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( | 150 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( |
| 149 env, cookies_); | 151 env, cookies_); |
| 152 ScopedJavaLocalRef<jstring> j_user_agent = ConvertUTF8ToJavaString( |
| 153 env, user_agent_); |
| 150 | 154 |
| 151 jobject j_context = base::android::GetApplicationContext(); | 155 jobject j_context = base::android::GetApplicationContext(); |
| 152 DCHECK(j_context); | 156 DCHECK(j_context); |
| 153 | 157 |
| 154 const std::string data_uri_prefix("data:"); | 158 const std::string data_uri_prefix("data:"); |
| 155 if (StartsWithASCII(url, data_uri_prefix, true)) { | 159 if (StartsWithASCII(url, data_uri_prefix, true)) { |
| 156 if (!Java_MediaPlayerBridge_setDataUriDataSource( | 160 if (!Java_MediaPlayerBridge_setDataUriDataSource( |
| 157 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj())) { | 161 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj())) { |
| 158 OnMediaError(MEDIA_ERROR_FORMAT); | 162 OnMediaError(MEDIA_ERROR_FORMAT); |
| 159 } | 163 } |
| 160 return; | 164 return; |
| 161 } | 165 } |
| 162 | 166 |
| 163 if (!Java_MediaPlayerBridge_setDataSource( | 167 if (!Java_MediaPlayerBridge_setDataSource( |
| 164 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj(), | 168 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj(), |
| 165 j_cookies.obj(), hide_url_log_)) { | 169 j_cookies.obj(), j_user_agent.obj(), hide_url_log_)) { |
| 166 OnMediaError(MEDIA_ERROR_FORMAT); | 170 OnMediaError(MEDIA_ERROR_FORMAT); |
| 167 return; | 171 return; |
| 168 } | 172 } |
| 169 | 173 |
| 170 manager()->RequestMediaResources(player_id()); | 174 manager()->RequestMediaResources(player_id()); |
| 171 if (!Java_MediaPlayerBridge_prepareAsync(env, j_media_player_bridge_.obj())) | 175 if (!Java_MediaPlayerBridge_prepareAsync(env, j_media_player_bridge_.obj())) |
| 172 OnMediaError(MEDIA_ERROR_FORMAT); | 176 OnMediaError(MEDIA_ERROR_FORMAT); |
| 173 } | 177 } |
| 174 | 178 |
| 175 void MediaPlayerBridge::OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, | 179 void MediaPlayerBridge::OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 453 |
| 450 GURL MediaPlayerBridge::GetUrl() { | 454 GURL MediaPlayerBridge::GetUrl() { |
| 451 return url_; | 455 return url_; |
| 452 } | 456 } |
| 453 | 457 |
| 454 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 458 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
| 455 return first_party_for_cookies_; | 459 return first_party_for_cookies_; |
| 456 } | 460 } |
| 457 | 461 |
| 458 } // namespace media | 462 } // namespace media |
| OLD | NEW |