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

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: rebase 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
« no previous file with comments | « media/base/android/media_player_android.cc ('k') | media/base/android/media_player_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 virtual base::TimeDelta GetCurrentTime() override; 67 virtual base::TimeDelta GetCurrentTime() override;
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 76
78 // MediaPlayerListener callbacks.
79 void OnVideoSizeChanged(int width, int height);
80 void OnMediaError(int error_type);
81 void OnBufferingUpdate(int percent);
82 void OnPlaybackComplete();
83 void OnMediaInterrupted();
84 void OnSeekComplete();
85 void OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, jboolean success); 77 void OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, jboolean success);
86 78
87 protected: 79 protected:
88 void SetJavaMediaPlayerBridge(jobject j_media_player_bridge); 80 void SetJavaMediaPlayerBridge(jobject j_media_player_bridge);
89 base::android::ScopedJavaLocalRef<jobject> GetJavaMediaPlayerBridge(); 81 base::android::ScopedJavaLocalRef<jobject> GetJavaMediaPlayerBridge();
90 void SetMediaPlayerListener();
91 void SetDuration(base::TimeDelta time); 82 void SetDuration(base::TimeDelta time);
92 83
93 virtual void PendingSeekInternal(const base::TimeDelta& time); 84 virtual void PendingSeekInternal(const base::TimeDelta& time);
94 85
95 // Prepare the player for playback, asynchronously. When succeeds, 86 // Prepare the player for playback, asynchronously. When succeeds,
96 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will 87 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will
97 // be called with an error type. 88 // be called with an error type.
98 virtual void Prepare(); 89 virtual void Prepare();
99 void OnMediaPrepared(); 90
91 // MediaPlayerAndroid implementation.
92 virtual void OnVideoSizeChanged(int width, int height) override;
93 virtual void OnPlaybackComplete() override;
94 virtual void OnMediaInterrupted() override;
95 virtual void OnMediaPrepared() override;
100 96
101 // Create the corresponding Java class instance. 97 // Create the corresponding Java class instance.
102 virtual void CreateJavaMediaPlayerBridge(); 98 virtual void CreateJavaMediaPlayerBridge();
103 99
104 // Get allowed operations from the player. 100 // Get allowed operations from the player.
105 virtual base::android::ScopedJavaLocalRef<jobject> GetAllowedOperations(); 101 virtual base::android::ScopedJavaLocalRef<jobject> GetAllowedOperations();
106 102
107 private: 103 private:
108 friend class MediaPlayerListener;
109
110 // Set the data source for the media player. 104 // Set the data source for the media player.
111 void SetDataSource(const std::string& url); 105 void SetDataSource(const std::string& url);
112 106
113 // Functions that implements media player control. 107 // Functions that implements media player control.
114 void StartInternal(); 108 void StartInternal();
115 void PauseInternal(); 109 void PauseInternal();
116 void SeekInternal(base::TimeDelta time); 110 void SeekInternal(base::TimeDelta time);
117 111
118 // Called when |time_update_timer_| fires. 112 // Called when |time_update_timer_| fires.
119 void OnTimeUpdateTimerFired(); 113 void OnTimeUpdateTimerFired();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 bool can_seek_backward_; 167 bool can_seek_backward_;
174 168
175 // Cookies for |url_|. 169 // Cookies for |url_|.
176 std::string cookies_; 170 std::string cookies_;
177 171
178 // Java MediaPlayerBridge instance. 172 // Java MediaPlayerBridge instance.
179 base::android::ScopedJavaGlobalRef<jobject> j_media_player_bridge_; 173 base::android::ScopedJavaGlobalRef<jobject> j_media_player_bridge_;
180 174
181 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_; 175 base::RepeatingTimer<MediaPlayerBridge> time_update_timer_;
182 176
183 // Listener object that listens to all the media player events.
184 scoped_ptr<MediaPlayerListener> listener_;
185
186 // Volume of playback. 177 // Volume of playback.
187 double volume_; 178 double volume_;
188 179
189 // Whether user credentials are allowed to be passed. 180 // Whether user credentials are allowed to be passed.
190 bool allow_credentials_; 181 bool allow_credentials_;
191 182
192 // Weak pointer passed to |listener_| for callbacks.
193 // NOTE: Weak pointers must be invalidated before all other member variables. 183 // NOTE: Weak pointers must be invalidated before all other member variables.
194 base::WeakPtrFactory<MediaPlayerBridge> weak_factory_; 184 base::WeakPtrFactory<MediaPlayerBridge> weak_factory_;
195 185
196 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge); 186 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridge);
197 }; 187 };
198 188
199 } // namespace media 189 } // namespace media
200 190
201 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_ 191 #endif // MEDIA_BASE_ANDROID_MEDIA_PLAYER_BRIDGE_H_
OLDNEW
« no previous file with comments | « media/base/android/media_player_android.cc ('k') | media/base/android/media_player_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698