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/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "jni/MediaPlayerBridge_jni.h" | 13 #include "jni/MediaPlayerBridge_jni.h" |
14 #include "jni/MediaPlayer_jni.h" | 14 #include "jni/MediaPlayer_jni.h" |
15 #include "media/base/android/cookie_getter.h" | |
16 #include "media/base/android/media_player_bridge_manager.h" | 15 #include "media/base/android/media_player_bridge_manager.h" |
| 16 #include "media/base/android/media_resource_getter.h" |
17 | 17 |
18 using base::android::AttachCurrentThread; | 18 using base::android::AttachCurrentThread; |
19 using base::android::CheckException; | 19 using base::android::CheckException; |
20 using base::android::ConvertUTF8ToJavaString; | 20 using base::android::ConvertUTF8ToJavaString; |
21 using base::android::GetClass; | 21 using base::android::GetClass; |
22 using base::android::JavaRef; | 22 using base::android::JavaRef; |
23 using base::android::MethodID; | 23 using base::android::MethodID; |
24 using base::android::ScopedJavaLocalRef; | 24 using base::android::ScopedJavaLocalRef; |
25 | 25 |
26 // These constants are from the android source tree and need to be kept in | 26 // These constants are from the android source tree and need to be kept in |
(...skipping 11 matching lines...) Expand all Loading... |
38 // the duration is unknown. And we scale the seek position later when duration | 38 // the duration is unknown. And we scale the seek position later when duration |
39 // is available. | 39 // is available. |
40 // TODO(qinmin): create a thread and use android MediaMetadataRetriever | 40 // TODO(qinmin): create a thread and use android MediaMetadataRetriever |
41 // class to extract the duration. | 41 // class to extract the duration. |
42 static const int kTemporaryDuration = 100; | 42 static const int kTemporaryDuration = 100; |
43 | 43 |
44 namespace media { | 44 namespace media { |
45 | 45 |
46 MediaPlayerBridge::MediaPlayerBridge( | 46 MediaPlayerBridge::MediaPlayerBridge( |
47 int player_id, | 47 int player_id, |
48 const std::string& url, | 48 const GURL& url, |
49 const std::string& first_party_for_cookies, | 49 const GURL& first_party_for_cookies, |
50 CookieGetter* cookie_getter, | 50 MediaResourceGetter* resource_getter, |
51 bool hide_url_log, | 51 bool hide_url_log, |
52 MediaPlayerBridgeManager* manager, | 52 MediaPlayerBridgeManager* manager, |
53 const MediaErrorCB& media_error_cb, | 53 const MediaErrorCB& media_error_cb, |
54 const VideoSizeChangedCB& video_size_changed_cb, | 54 const VideoSizeChangedCB& video_size_changed_cb, |
55 const BufferingUpdateCB& buffering_update_cb, | 55 const BufferingUpdateCB& buffering_update_cb, |
56 const MediaPreparedCB& media_prepared_cb, | 56 const MediaPreparedCB& media_prepared_cb, |
57 const PlaybackCompleteCB& playback_complete_cb, | 57 const PlaybackCompleteCB& playback_complete_cb, |
58 const SeekCompleteCB& seek_complete_cb, | 58 const SeekCompleteCB& seek_complete_cb, |
59 const TimeUpdateCB& time_update_cb, | 59 const TimeUpdateCB& time_update_cb, |
60 const MediaInterruptedCB& media_interrupted_cb) | 60 const MediaInterruptedCB& media_interrupted_cb) |
(...skipping 12 matching lines...) Expand all Loading... |
73 first_party_for_cookies_(first_party_for_cookies), | 73 first_party_for_cookies_(first_party_for_cookies), |
74 has_cookies_(false), | 74 has_cookies_(false), |
75 hide_url_log_(hide_url_log), | 75 hide_url_log_(hide_url_log), |
76 duration_(base::TimeDelta::FromSeconds(kTemporaryDuration)), | 76 duration_(base::TimeDelta::FromSeconds(kTemporaryDuration)), |
77 width_(0), | 77 width_(0), |
78 height_(0), | 78 height_(0), |
79 can_pause_(true), | 79 can_pause_(true), |
80 can_seek_forward_(true), | 80 can_seek_forward_(true), |
81 can_seek_backward_(true), | 81 can_seek_backward_(true), |
82 manager_(manager), | 82 manager_(manager), |
83 cookie_getter_(cookie_getter), | 83 resource_getter_(resource_getter), |
84 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), | 84 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), |
85 listener_(base::MessageLoopProxy::current(), | 85 listener_(base::MessageLoopProxy::current(), |
86 weak_this_.GetWeakPtr()) {} | 86 weak_this_.GetWeakPtr()) {} |
87 | 87 |
88 MediaPlayerBridge::~MediaPlayerBridge() { | 88 MediaPlayerBridge::~MediaPlayerBridge() { |
89 Release(); | 89 Release(); |
90 } | 90 } |
91 | 91 |
92 void MediaPlayerBridge::InitializePlayer() { | 92 void MediaPlayerBridge::InitializePlayer() { |
93 JNIEnv* env = AttachCurrentThread(); | 93 JNIEnv* env = AttachCurrentThread(); |
(...skipping 18 matching lines...) Expand all Loading... |
112 env, j_media_player_.obj(), surface); | 112 env, j_media_player_.obj(), surface); |
113 } | 113 } |
114 | 114 |
115 void MediaPlayerBridge::Prepare() { | 115 void MediaPlayerBridge::Prepare() { |
116 if (j_media_player_.is_null()) | 116 if (j_media_player_.is_null()) |
117 InitializePlayer(); | 117 InitializePlayer(); |
118 | 118 |
119 if (has_cookies_) { | 119 if (has_cookies_) { |
120 GetCookiesCallback(cookies_); | 120 GetCookiesCallback(cookies_); |
121 } else { | 121 } else { |
122 cookie_getter_->GetCookies(url_, first_party_for_cookies_, base::Bind( | 122 resource_getter_->GetCookies(url_, first_party_for_cookies_, base::Bind( |
123 &MediaPlayerBridge::GetCookiesCallback, weak_this_.GetWeakPtr())); | 123 &MediaPlayerBridge::GetCookiesCallback, weak_this_.GetWeakPtr())); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 void MediaPlayerBridge::GetCookiesCallback(const std::string& cookies) { | 127 void MediaPlayerBridge::GetCookiesCallback(const std::string& cookies) { |
128 cookies_ = cookies; | 128 cookies_ = cookies; |
129 has_cookies_ = true; | 129 has_cookies_ = true; |
| 130 |
130 if (j_media_player_.is_null()) | 131 if (j_media_player_.is_null()) |
131 return; | 132 return; |
132 | 133 |
| 134 if (url_.SchemeIsFileSystem()) { |
| 135 resource_getter_->GetPlatformPathFromFileSystemURL(url_, base::Bind( |
| 136 &MediaPlayerBridge::SetDataSource, weak_this_.GetWeakPtr())); |
| 137 } else { |
| 138 SetDataSource(url_.spec()); |
| 139 } |
| 140 } |
| 141 |
| 142 void MediaPlayerBridge::SetDataSource(const std::string& url) { |
| 143 if (j_media_player_.is_null()) |
| 144 return; |
| 145 |
133 JNIEnv* env = AttachCurrentThread(); | 146 JNIEnv* env = AttachCurrentThread(); |
134 CHECK(env); | 147 CHECK(env); |
135 | 148 |
136 // Create a Java String for the URL. | 149 // Create a Java String for the URL. |
137 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url_); | 150 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); |
138 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( | 151 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( |
139 env, cookies_); | 152 env, cookies_); |
140 | 153 |
141 jobject j_context = base::android::GetApplicationContext(); | 154 jobject j_context = base::android::GetApplicationContext(); |
142 DCHECK(j_context); | 155 DCHECK(j_context); |
143 | 156 |
144 if (Java_MediaPlayerBridge_setDataSource( | 157 if (Java_MediaPlayerBridge_setDataSource( |
145 env, j_media_player_.obj(), j_context, j_url_string.obj(), | 158 env, j_media_player_.obj(), j_context, j_url_string.obj(), |
146 j_cookies.obj(), hide_url_log_)) { | 159 j_cookies.obj(), hide_url_log_)) { |
147 if (manager_) | 160 if (manager_) |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 399 |
387 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) { | 400 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) { |
388 bool ret = RegisterNativesImpl(env); | 401 bool ret = RegisterNativesImpl(env); |
389 DCHECK(g_MediaPlayerBridge_clazz); | 402 DCHECK(g_MediaPlayerBridge_clazz); |
390 if (ret) | 403 if (ret) |
391 ret = JNI_MediaPlayer::RegisterNativesImpl(env); | 404 ret = JNI_MediaPlayer::RegisterNativesImpl(env); |
392 return ret; | 405 return ret; |
393 } | 406 } |
394 | 407 |
395 } // namespace media | 408 } // namespace media |
OLD | NEW |