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/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/timer.h" | 14 #include "base/timer.h" |
15 | 15 |
16 namespace webkit_media { | |
17 struct MediaMetadataAndroid; | |
18 } | |
19 | |
20 namespace content { | 16 namespace content { |
21 | 17 |
22 class MediaPlayerDelegateAndroid; | 18 class MediaPlayerManagerAndroid; |
23 | 19 |
24 // Native mirror of ContentVideoView.java. | 20 // 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 // it. It accepts media control from Java class, and forwards it to | |
23 // MediaPlayerManagerAndroid. | |
25 class ContentVideoView { | 24 class ContentVideoView { |
26 public: | 25 public: |
27 ContentVideoView(); | 26 // Construct a ContentVideoView object. The |manager| will handle all the |
27 // playback controls from the Java class. | |
28 explicit ContentVideoView(MediaPlayerManagerAndroid* manager); | |
28 ~ContentVideoView(); | 29 ~ContentVideoView(); |
29 | 30 |
30 static bool RegisterContentVideoView(JNIEnv* env); | 31 static bool RegisterContentVideoView(JNIEnv* env); |
31 void Init(JNIEnv*, jobject obj, jobject weak_this); | |
32 | 32 |
33 // -------------------------------------------------------------------------- | 33 // Getter method called by the Java class to get the media information. |
34 // All these functions are called on UI thread | |
35 int GetVideoWidth(JNIEnv*, jobject obj) const; | 34 int GetVideoWidth(JNIEnv*, jobject obj) const; |
36 int GetVideoHeight(JNIEnv*, jobject obj) const; | 35 int GetVideoHeight(JNIEnv*, jobject obj) const; |
37 int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const; | 36 int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const; |
38 int GetCurrentPosition(JNIEnv*, jobject obj) const; | 37 int GetCurrentPosition(JNIEnv*, jobject obj) const; |
39 bool IsPlaying(JNIEnv*, jobject obj); | 38 bool IsPlaying(JNIEnv*, jobject obj); |
39 void UpdateMediaMetadata(JNIEnv*, jobject obj); | |
40 | |
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 | |
46 // |release_media_player| is true, |manager_| needs to release the player | |
47 // as we are quitting the app. | |
48 void ExitFullscreen(JNIEnv*, jobject, jboolean release_media_player); | |
scherkus (not reviewing)
2012/10/02 16:20:16
is it guaranteed that no more methods get called o
qinmin
2012/10/03 02:32:48
Yes, ExitFullscreen should be the last call the ja
| |
49 | |
50 // Media control method called by the Java class. | |
40 void SeekTo(JNIEnv*, jobject obj, jint msec); | 51 void SeekTo(JNIEnv*, jobject obj, jint msec); |
41 int GetPlayerId(JNIEnv*, jobject obj) const; | |
42 int GetRouteId(JNIEnv*, jobject obj) const; | |
43 int GetRenderHandle(JNIEnv*, jobject obj) const; | |
44 void Play(JNIEnv*, jobject obj); | 52 void Play(JNIEnv*, jobject obj); |
45 void Pause(JNIEnv*, jobject obj); | 53 void Pause(JNIEnv*, jobject obj); |
46 // -------------------------------------------------------------------------- | |
47 | 54 |
48 void PrepareAsync(); | 55 // Called by the Java class to pass the surface object to the player. |
49 void DestroyContentVideoView(); | |
50 void UpdateMediaMetadata(JNIEnv*, jobject obj); | |
51 void DestroyContentVideoView(JNIEnv*, jobject); | |
52 void DestroyContentVideoView(JNIEnv*, jobject, jboolean release_media_player); | |
53 void CreateContentVideoView(MediaPlayerDelegateAndroid* player); | |
54 void SetSurface(JNIEnv*, | 56 void SetSurface(JNIEnv*, |
scherkus (not reviewing)
2012/10/02 16:20:16
nit: this looks like it can now fit on one line
qinmin
2012/10/03 02:32:48
Done.
| |
55 jobject obj, | 57 jobject obj, |
56 jobject surface, | 58 jobject surface); |
57 jint route_id, | 59 |
58 jint player_id); | 60 // Method called by |manager_| to inform the Java class about player status |
61 // change. | |
59 void UpdateMediaMetadata(); | 62 void UpdateMediaMetadata(); |
60 | |
61 void OnMediaPlayerError(int errorType); | 63 void OnMediaPlayerError(int errorType); |
62 void OnVideoSizeChanged(int width, int height); | 64 void OnVideoSizeChanged(int width, int height); |
63 void OnBufferingUpdate(int percent); | 65 void OnBufferingUpdate(int percent); |
64 void OnPlaybackComplete(); | 66 void OnPlaybackComplete(); |
65 | 67 |
66 private: | 68 private: |
67 // In some certain cases if the renderer crashes, the ExitFullscreen message | 69 // Object that manages the fullscreen media player. It is responsible for |
68 // will never acknowledged by the renderer. | 70 // handling all the playback controls. |
69 void OnTimeout(); | 71 MediaPlayerManagerAndroid* manager_; |
70 | 72 |
71 webkit_media::MediaMetadataAndroid* GetMediaMetadata(); | 73 // Reference to the Java object. |
72 | |
73 int ConvertSecondsToMilliSeconds(float seconds) const; | |
74 | |
75 MediaPlayerDelegateAndroid* player_; | |
76 | |
77 base::android::ScopedJavaGlobalRef<jobject> j_content_video_view_; | 74 base::android::ScopedJavaGlobalRef<jobject> j_content_video_view_; |
78 | 75 |
79 // A timer to keep track of when the acknowledgement of exitfullscreen | |
80 // message times out. | |
81 base::OneShotTimer<ContentVideoView> timeout_timer_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(ContentVideoView); | 76 DISALLOW_COPY_AND_ASSIGN(ContentVideoView); |
84 }; | 77 }; |
85 | 78 |
86 } // namespace content | 79 } // namespace content |
87 | 80 |
88 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ | 81 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIDEO_VIEW_H_ |
OLD | NEW |