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 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/android/jni_helper.h" | |
10 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/timer.h" | 15 #include "base/timer.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class MediaPlayerManagerAndroid; | 19 class MediaPlayerManagerAndroid; |
19 | 20 |
20 // Native mirror of ContentVideoView.java. This class is responsible for | 21 // Native mirror of ContentVideoView.java. This class is responsible for |
21 // creating the Java video view and pass all the player status change to | 22 // creating the Java video view and pass all the player status change to |
22 // it. It accepts media control from Java class, and forwards it to | 23 // it. It accepts media control from Java class, and forwards it to |
23 // MediaPlayerManagerAndroid. | 24 // MediaPlayerManagerAndroid. |
24 class ContentVideoView { | 25 class ContentVideoView { |
25 public: | 26 public: |
26 // Construct a ContentVideoView object. The |manager| will handle all the | 27 // Construct a ContentVideoView object. The |manager| will handle all the |
27 // playback controls from the Java class. | 28 // playback controls from the Java class. |
28 explicit ContentVideoView(MediaPlayerManagerAndroid* manager); | 29 ContentVideoView( |
30 const base::android::ScopedJavaLocalRef<jobject>& context, | |
31 const base::android::ScopedJavaLocalRef<jobject>& client, | |
32 MediaPlayerManagerAndroid* manager); | |
33 | |
29 ~ContentVideoView(); | 34 ~ContentVideoView(); |
30 | 35 |
36 // To open another video on existing ContentVideoView. | |
37 void OpenVideo(); | |
38 | |
31 static bool RegisterContentVideoView(JNIEnv* env); | 39 static bool RegisterContentVideoView(JNIEnv* env); |
32 | 40 |
33 // Getter method called by the Java class to get the media information. | 41 // Getter method called by the Java class to get the media information. |
34 int GetVideoWidth(JNIEnv*, jobject obj) const; | 42 int GetVideoWidth(JNIEnv*, jobject obj) const; |
35 int GetVideoHeight(JNIEnv*, jobject obj) const; | 43 int GetVideoHeight(JNIEnv*, jobject obj) const; |
36 int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const; | 44 int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const; |
37 int GetCurrentPosition(JNIEnv*, jobject obj) const; | 45 int GetCurrentPosition(JNIEnv*, jobject obj) const; |
38 bool IsPlaying(JNIEnv*, jobject obj); | 46 bool IsPlaying(JNIEnv*, jobject obj); |
39 void UpdateMediaMetadata(JNIEnv*, jobject obj); | 47 void UpdateMediaMetadata(JNIEnv*, jobject obj); |
40 | 48 |
41 // Method to create and destroy the Java view. | |
42 void DestroyContentVideoView(); | |
43 void CreateContentVideoView(); | |
44 | |
45 // Called when the Java fullscreen view is destroyed. If | 49 // Called when the Java fullscreen view is destroyed. If |
46 // |release_media_player| is true, |manager_| needs to release the player | 50 // |release_media_player| is true, |manager_| needs to release the player |
47 // as we are quitting the app. | 51 // as we are quitting the app. |
48 void ExitFullscreen(JNIEnv*, jobject, jboolean release_media_player); | 52 void ExitFullscreen(JNIEnv*, jobject, jboolean release_media_player); |
49 | 53 |
50 // Media control method called by the Java class. | 54 // Media control method called by the Java class. |
51 void SeekTo(JNIEnv*, jobject obj, jint msec); | 55 void SeekTo(JNIEnv*, jobject obj, jint msec); |
52 void Play(JNIEnv*, jobject obj); | 56 void Play(JNIEnv*, jobject obj); |
53 void Pause(JNIEnv*, jobject obj); | 57 void Pause(JNIEnv*, jobject obj); |
54 | 58 |
55 // Called by the Java class to pass the surface object to the player. | 59 // Called by the Java class to pass the surface object to the player. |
56 void SetSurface(JNIEnv*, jobject obj, jobject surface); | 60 void SetSurface(JNIEnv*, jobject obj, jobject surface); |
57 | 61 |
58 // Method called by |manager_| to inform the Java class about player status | 62 // Method called by |manager_| to inform the Java class about player status |
59 // change. | 63 // change. |
60 void UpdateMediaMetadata(); | 64 void UpdateMediaMetadata(); |
61 void OnMediaPlayerError(int errorType); | 65 void OnMediaPlayerError(int errorType); |
62 void OnVideoSizeChanged(int width, int height); | 66 void OnVideoSizeChanged(int width, int height); |
63 void OnBufferingUpdate(int percent); | 67 void OnBufferingUpdate(int percent); |
64 void OnPlaybackComplete(); | 68 void OnPlaybackComplete(); |
69 void OnExitFullscreen(); | |
70 | |
71 // Return the corresponing ContentVideoView Java object if any. | |
72 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); | |
65 | 73 |
66 private: | 74 private: |
67 // Object that manages the fullscreen media player. It is responsible for | 75 // Object that manages the fullscreen media player. It is responsible for |
68 // handling all the playback controls. | 76 // handling all the playback controls. |
69 MediaPlayerManagerAndroid* manager_; | 77 MediaPlayerManagerAndroid* manager_; |
70 | 78 |
71 // Reference to the Java object. | 79 // Weak reference of corresponding Java object. |
72 base::android::ScopedJavaGlobalRef<jobject> j_content_video_view_; | 80 scoped_ptr<JavaObjectWeakGlobalRef> j_content_video_view_; |
joth
2013/05/15 22:38:57
no need for scoped_ptr, just have the JavaObjectWe
michaelbai
2013/05/22 18:08:39
Done.
| |
73 | 81 |
74 DISALLOW_COPY_AND_ASSIGN(ContentVideoView); | 82 DISALLOW_COPY_AND_ASSIGN(ContentVideoView); |
75 }; | 83 }; |
76 | 84 |
77 } // namespace content | 85 } // namespace content |
78 | 86 |
79 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 87 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
OLD | NEW |