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

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

Issue 643353002: Listen to the audio focus event for MSE/EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
19 #include "media/base/android/media_player_android.h" 19 #include "media/base/android/media_player_android.h"
20 #include "media/base/android/media_player_listener.h"
21 #include "url/gurl.h" 20 #include "url/gurl.h"
22 21
23 namespace media { 22 namespace media {
24 23
25 class MediaPlayerManager; 24 class MediaPlayerManager;
26 25
27 // This class serves as a bridge between the native code and Android MediaPlayer 26 // This class serves as a bridge between the native code and Android MediaPlayer
28 // Java class. For more information on Android MediaPlayer, check 27 // Java class. For more information on Android MediaPlayer, check
29 // http://developer.android.com/reference/android/media/MediaPlayer.html 28 // http://developer.android.com/reference/android/media/MediaPlayer.html
30 // The actual Android MediaPlayer instance is created lazily when Start(), 29 // The actual Android MediaPlayer instance is created lazily when Start(),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 virtual base::TimeDelta GetDuration() override; 68 virtual base::TimeDelta GetDuration() override;
70 virtual bool IsPlaying() override; 69 virtual bool IsPlaying() override;
71 virtual bool CanPause() override; 70 virtual bool CanPause() override;
72 virtual bool CanSeekForward() override; 71 virtual bool CanSeekForward() override;
73 virtual bool CanSeekBackward() override; 72 virtual bool CanSeekBackward() override;
74 virtual bool IsPlayerReady() override; 73 virtual bool IsPlayerReady() override;
75 virtual GURL GetUrl() override; 74 virtual GURL GetUrl() override;
76 virtual GURL GetFirstPartyForCookies() override; 75 virtual GURL GetFirstPartyForCookies() override;
77 virtual bool IsSurfaceInUse() const override; 76 virtual bool IsSurfaceInUse() const override;
78 77
79 // MediaPlayerListener callbacks.
80 void OnVideoSizeChanged(int width, int height);
81 void OnMediaError(int error_type);
82 void OnBufferingUpdate(int percent);
83 void OnPlaybackComplete();
84 void OnMediaInterrupted();
85 void OnSeekComplete();
86 void OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, jboolean success); 78 void OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, jboolean success);
87 79
88 protected: 80 protected:
89 void SetJavaMediaPlayerBridge(jobject j_media_player_bridge); 81 void SetJavaMediaPlayerBridge(jobject j_media_player_bridge);
90 base::android::ScopedJavaLocalRef<jobject> GetJavaMediaPlayerBridge(); 82 base::android::ScopedJavaLocalRef<jobject> GetJavaMediaPlayerBridge();
91 void SetMediaPlayerListener();
92 void SetDuration(base::TimeDelta time); 83 void SetDuration(base::TimeDelta time);
93 84
94 virtual void PendingSeekInternal(const base::TimeDelta& time); 85 virtual void PendingSeekInternal(const base::TimeDelta& time);
95 86
96 // Prepare the player for playback, asynchronously. When succeeds, 87 // Prepare the player for playback, asynchronously. When succeeds,
97 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will 88 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will
98 // be called with an error type. 89 // be called with an error type.
99 virtual void Prepare(); 90 virtual void Prepare();
100 void OnMediaPrepared(); 91
92 // MediaPlayerAndroid implementation.
93 virtual void OnVideoSizeChanged(int width, int height) override;
94 virtual void OnPlaybackComplete() override;
95 virtual void OnMediaInterrupted() override;
96 virtual void OnMediaPrepared() override;
101 97
102 // Create the corresponding Java class instance. 98 // Create the corresponding Java class instance.
103 virtual void CreateJavaMediaPlayerBridge(); 99 virtual void CreateJavaMediaPlayerBridge();
104 100
105 // Get allowed operations from the player. 101 // Get allowed operations from the player.
106 virtual base::android::ScopedJavaLocalRef<jobject> GetAllowedOperations(); 102 virtual base::android::ScopedJavaLocalRef<jobject> GetAllowedOperations();
107 103
108 private: 104 private:
109 friend class MediaPlayerListener;
110
111 // Set the data source for the media player. 105 // Set the data source for the media player.
112 void SetDataSource(const std::string& url); 106 void SetDataSource(const std::string& url);
113 107
114 // Functions that implements media player control. 108 // Functions that implements media player control.
115 void StartInternal(); 109 void StartInternal();
116 void PauseInternal(); 110 void PauseInternal();
117 void SeekInternal(base::TimeDelta time); 111 void SeekInternal(base::TimeDelta time);
118 112
119 // Called when |time_update_timer_| fires. 113 // Called when |time_update_timer_| fires.
120 void OnTimeUpdateTimerFired(); 114 void OnTimeUpdateTimerFired();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bool can_seek_backward_; 168 bool can_seek_backward_;
175 169
176 // Cookies for |url_|. 170 // Cookies for |url_|.
177 std::string cookies_; 171 std::string cookies_;
178 172
179 // Java MediaPlayerBridge instance. 173 // Java MediaPlayerBridge instance.
180 base::android::ScopedJavaGlobalRef<jobject> j_media_player_bridge_; 174 base::android::ScopedJavaGlobalRef<jobject> j_media_player_bridge_;
181 175
182 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; 176 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_;
183 177
184 // Listener object that listens to all the media player events.
185 scoped_ptr<MediaPlayerListener> listener_;
186
187 // Whether player is currently using a surface. 178 // Whether player is currently using a surface.
188 bool is_surface_in_use_; 179 bool is_surface_in_use_;
189 180
190 // Volume of playback. 181 // Volume of playback.
191 double volume_; 182 double volume_;
192 183
193 // Whether user credentials are allowed to be passed. 184 // Whether user credentials are allowed to be passed.
194 bool allow_credentials_; 185 bool allow_credentials_;
195 186
196 // Weak pointer passed to |listener_| for callbacks.
197 // NOTE: Weak pointers must be invalidated before all other member variables. 187 // NOTE: Weak pointers must be invalidated before all other member variables.
198 base::WeakPtrFactory<MediaPlayerBridge> weak_factory_; 188 base::WeakPtrFactory<MediaPlayerBridge> weak_factory_;
199 189
200 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); 190 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge);
201 }; 191 };
202 192
203 } // namespace media 193 } // namespace media
204 194
205 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 195 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698