Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / media / android / remote / remote_media_player_bridge.h
blobf1f506c0f3735028c0b17db5c138d54ba34f064c
1 // Copyright 2013 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 CHROME_BROWSER_MEDIA_ANDROID_REMOTE_REMOTE_MEDIA_PLAYER_BRIDGE_H_
6 #define CHROME_BROWSER_MEDIA_ANDROID_REMOTE_REMOTE_MEDIA_PLAYER_BRIDGE_H_
8 #include <jni.h>
9 #include <vector>
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "media/base/android/media_player_bridge.h"
15 class SkBitmap;
17 // This is the version of MediaPlayerBridge that handles the remote media
18 // playback.
20 namespace remote_media {
22 class RemoteMediaPlayerManager;
24 class RemoteMediaPlayerBridge : public media::MediaPlayerAndroid {
25 public:
26 RemoteMediaPlayerBridge(
27 MediaPlayerAndroid* local_player,
28 const std::string& user_agent,
29 bool hide_url_log,
30 RemoteMediaPlayerManager* manager);
31 ~RemoteMediaPlayerBridge() override;
33 static bool RegisterRemoteMediaPlayerBridge(JNIEnv* env);
35 // Initialize this object.
36 virtual void Initialize();
38 // MediaPlayerAndroid implementation.
39 void SetVideoSurface(gfx::ScopedJavaSurface surface) override;
40 void Start() override;
41 void Pause(bool is_media_related_action) override;
42 void SeekTo(base::TimeDelta timestamp) override;
43 void Release() override;
44 void SetVolume(double volume) override;
45 int GetVideoWidth() override;
46 int GetVideoHeight() override;
47 base::TimeDelta GetCurrentTime() override;
48 base::TimeDelta GetDuration() override;
49 bool IsPlaying() override;
50 bool CanPause() override;
51 bool CanSeekForward() override;
52 bool CanSeekBackward() override;
53 bool IsPlayerReady() override;
54 GURL GetUrl() override;
55 GURL GetFirstPartyForCookies() override;
57 // JNI functions
58 base::android::ScopedJavaLocalRef<jstring> GetFrameUrl(
59 JNIEnv* env, jobject obj);
60 void OnPlaying(JNIEnv* env, jobject obj);
61 void OnPaused(JNIEnv* env, jobject obj);
62 void OnRouteSelected(JNIEnv* env, jobject obj, jstring castingMessage);
63 void OnRouteUnselected(JNIEnv* env, jobject obj);
64 void OnPlaybackFinished(JNIEnv* env, jobject obj);
65 void OnRouteAvailabilityChanged(JNIEnv* env, jobject obj, jboolean available);
66 base::android::ScopedJavaLocalRef<jstring> GetTitle(JNIEnv* env, jobject obj);
68 // Wrappers for calls to Java used by the remote media player manager
69 void RequestRemotePlayback();
70 void RequestRemotePlaybackControl();
71 void SetNativePlayer();
72 void OnPlayerCreated();
73 void OnPlayerDestroyed();
74 bool IsRemotePlaybackAvailable() const;
75 bool IsRemotePlaybackPreferredForFrame() const;
77 // Returns true if the we can play the media remotely
78 bool IsMediaPlayableRemotely() const;
80 // Gets the message to display on the embedded player while casting.
81 std::string GetCastingMessage();
83 // Tell the java side about the poster image for a given media.
84 void SetPosterBitmap(const std::vector<SkBitmap>& bitmaps);
86 protected:
87 // MediaPlayerAndroid implementation.
88 void OnVideoSizeChanged(int width, int height) override;
89 void OnPlaybackComplete() override;
90 void OnMediaInterrupted() override;
91 void OnMediaPrepared() override;
93 private:
94 // Functions that implements media player control.
95 void StartInternal();
96 void PauseInternal();
97 void SeekInternal(base::TimeDelta time);
99 // Called when |time_update_timer_| fires.
100 void OnTimeUpdateTimerFired();
102 // Callback function passed to |resource_getter_|. Called when the cookies
103 // are retrieved.
104 void OnCookiesRetrieved(const std::string& cookies);
106 void PendingSeekInternal(const base::TimeDelta& time);
108 // Prepare the player for playback, asynchronously. When succeeds,
109 // OnMediaPrepared() will be called. Otherwise, OnMediaError() will
110 // be called with an error type.
111 void Prepare();
113 long start_position_millis_;
114 MediaPlayerAndroid* local_player_;
115 bool in_use_;
116 bool prepared_;
117 bool pending_play_;
118 int width_;
119 int height_;
120 base::RepeatingTimer<RemoteMediaPlayerBridge> time_update_timer_;
121 base::TimeDelta duration_;
122 bool should_seek_on_prepare_;
123 base::TimeDelta pending_seek_;
125 // Hide url log from media player.
126 bool hide_url_log_;
128 // Volume of playback.
129 double volume_;
131 // Url for playback.
132 GURL url_;
134 // First party url for cookies.
135 GURL first_party_for_cookies_;
137 // Cookies for |url_|.
138 std::string cookies_;
140 // User agent string to be used for media player.
141 const std::string user_agent_;
143 base::android::ScopedJavaGlobalRef<jobject> java_bridge_;
144 scoped_ptr<std::string> casting_message_;
146 // NOTE: Weak pointers must be invalidated before all other member variables.
147 base::WeakPtrFactory<RemoteMediaPlayerBridge> weak_factory_;
149 DISALLOW_COPY_AND_ASSIGN(RemoteMediaPlayerBridge);
152 } // namespace remote_media
154 #endif // CHROME_BROWSER_MEDIA_ANDROID_REMOTE_REMOTE_MEDIA_PLAYER_BRIDGE_H_