Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: media/base/android/media_player_bridge.cc

Issue 12625005: remove call to get android MediaPlayer class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moving getMetadata() call to java side Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 15 #include "media/base/android/cookie_getter.h"
16 #include "media/base/android/media_player_bridge_manager.h" 16 #include "media/base/android/media_player_bridge_manager.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;
Yaron 2013/03/12 21:51:54 Update these. Please remove unnecessary ones and i
qinmin 2013/03/12 22:27:32 Done.
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
27 // sync with android/media/MediaMetadata.java. 27 // sync with android/media/MediaMetadata.java.
28 static const jint kPauseAvailable = 1; 28 static const jint kPauseAvailable = 1;
29 static const jint kSeekBackwardAvailable = 2; 29 static const jint kSeekBackwardAvailable = 2;
30 static const jint kSeekForwardAvailable = 3; 30 static const jint kSeekForwardAvailable = 3;
31 31
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 321
322 GetMetadata(); 322 GetMetadata();
323 323
324 media_prepared_cb_.Run(player_id_, duration_); 324 media_prepared_cb_.Run(player_id_, duration_);
325 } 325 }
326 326
327 void MediaPlayerBridge::GetMetadata() { 327 void MediaPlayerBridge::GetMetadata() {
328 JNIEnv* env = AttachCurrentThread(); 328 JNIEnv* env = AttachCurrentThread();
329 CHECK(env); 329 CHECK(env);
330 330
331 ScopedJavaLocalRef<jclass> media_player_class( 331 ScopedJavaLocalRef<jbooleanArray> boolean_array =
332 GetClass(env, "android/media/MediaPlayer")); 332 Java_MediaPlayerBridge_getMetadata(env, j_media_player_.obj());
333 jmethodID method = MethodID::Get<MethodID::TYPE_INSTANCE>( 333 jboolean* bools = env->GetBooleanArrayElements(boolean_array.obj(), NULL);
334 env, media_player_class.obj(), "getMetadata",
335 "(ZZ)Landroid/media/Metadata;");
336 ScopedJavaLocalRef<jobject> j_metadata(
337 env, env->CallObjectMethod(
338 j_media_player_.obj(), method, JNI_FALSE, JNI_FALSE));
339 CheckException(env); 334 CheckException(env);
340 if (j_metadata.is_null())
341 return;
342 335
343 ScopedJavaLocalRef<jclass> metadata_class( 336 can_pause_ = bools[0];
344 GetClass(env, "android/media/Metadata")); 337 can_seek_forward_ = bools[1];
345 jmethodID get_boolean = MethodID::Get<MethodID::TYPE_INSTANCE>( 338 can_seek_backward_ = bools[2];
346 env, metadata_class.obj(), "getBoolean", "(I)Z"); 339 env->ReleaseBooleanArrayElements(boolean_array.obj(), bools, JNI_ABORT);
347 can_pause_ = env->CallBooleanMethod(j_metadata.obj(),
348 get_boolean,
349 kPauseAvailable);
350 CheckException(env);
351 can_seek_forward_ = env->CallBooleanMethod(j_metadata.obj(),
352 get_boolean,
353 kSeekBackwardAvailable);
354 CheckException(env);
355 can_seek_backward_ = env->CallBooleanMethod(j_metadata.obj(),
356 get_boolean,
357 kSeekForwardAvailable);
358 CheckException(env);
359 } 340 }
360 341
361 void MediaPlayerBridge::StartInternal() { 342 void MediaPlayerBridge::StartInternal() {
362 JNIEnv* env = AttachCurrentThread(); 343 JNIEnv* env = AttachCurrentThread();
363 JNI_MediaPlayer::Java_MediaPlayer_start(env, j_media_player_.obj()); 344 JNI_MediaPlayer::Java_MediaPlayer_start(env, j_media_player_.obj());
364 if (!time_update_timer_.IsRunning()) { 345 if (!time_update_timer_.IsRunning()) {
365 time_update_timer_.Start( 346 time_update_timer_.Start(
366 FROM_HERE, 347 FROM_HERE,
367 base::TimeDelta::FromMilliseconds(kTimeUpdateInterval), 348 base::TimeDelta::FromMilliseconds(kTimeUpdateInterval),
368 this, &MediaPlayerBridge::DoTimeUpdate); 349 this, &MediaPlayerBridge::DoTimeUpdate);
(...skipping 17 matching lines...) Expand all
386 367
387 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) { 368 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) {
388 bool ret = RegisterNativesImpl(env); 369 bool ret = RegisterNativesImpl(env);
389 DCHECK(g_MediaPlayerBridge_clazz); 370 DCHECK(g_MediaPlayerBridge_clazz);
390 if (ret) 371 if (ret)
391 ret = JNI_MediaPlayer::RegisterNativesImpl(env); 372 ret = JNI_MediaPlayer::RegisterNativesImpl(env);
392 return ret; 373 return ret;
393 } 374 }
394 375
395 } // namespace media 376 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698