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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_LISTENER_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_LISTENER_H_
10 #include "base/android/scoped_java_ref.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
15 class SingleThreadTaskRunner;
20 class MediaPlayerAndroid;
22 // Acts as a thread proxy between java MediaPlayerListener object and
23 // MediaPlayerAndroid so that callbacks are posted onto the UI thread.
24 class MediaPlayerListener {
26 // Construct a native MediaPlayerListener object. Callbacks from the java
27 // side object will be forwarded to |media_player| by posting a task on the
30 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
31 base::WeakPtr<MediaPlayerAndroid> media_player);
32 virtual ~MediaPlayerListener();
34 // Called by the Java MediaPlayerListener and mirrored to corresponding
36 void OnMediaError(JNIEnv* /* env */, jobject /* obj */, jint error_type);
37 void OnVideoSizeChanged(JNIEnv* /* env */, jobject /* obj */,
38 jint width, jint height);
39 void OnBufferingUpdate(JNIEnv* /* env */, jobject /* obj */, jint percent);
40 void OnPlaybackComplete(JNIEnv* /* env */, jobject /* obj */);
41 void OnSeekComplete(JNIEnv* /* env */, jobject /* obj */);
42 void OnMediaPrepared(JNIEnv* /* env */, jobject /* obj */);
43 void OnMediaInterrupted(JNIEnv* /* env */, jobject /* obj */);
45 // Create a Java MediaPlayerListener object and listens to all the media
46 // related events from system and |media_player|. If |media_player| is NULL,
47 // this class only listens to system events.
48 void CreateMediaPlayerListener(jobject context, jobject media_player);
49 void ReleaseMediaPlayerListenerResources();
51 // Register MediaPlayerListener in the system library loader.
52 static bool RegisterMediaPlayerListener(JNIEnv* env);
55 // The message loop where |media_player_| lives.
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
58 // The MediaPlayerAndroid object all the callbacks should be sent to.
59 base::WeakPtr<MediaPlayerAndroid> media_player_;
61 base::android::ScopedJavaGlobalRef<jobject> j_media_player_listener_;
63 DISALLOW_COPY_AND_ASSIGN(MediaPlayerListener);
68 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_LISTENER_H_