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_
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "media/base/android/media_player_bridge.h"
17 // This is the version of MediaPlayerBridge that handles the remote media
20 namespace remote_media
{
22 class RemoteMediaPlayerManager
;
24 class RemoteMediaPlayerBridge
: public media::MediaPlayerAndroid
{
26 RemoteMediaPlayerBridge(
27 MediaPlayerAndroid
* local_player
,
28 const std::string
& user_agent
,
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
;
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
);
87 // MediaPlayerAndroid implementation.
88 void OnVideoSizeChanged(int width
, int height
) override
;
89 void OnPlaybackComplete() override
;
90 void OnMediaInterrupted() override
;
91 void OnMediaPrepared() override
;
94 // Functions that implements media player control.
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
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.
113 long start_position_millis_
;
114 MediaPlayerAndroid
* local_player_
;
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.
128 // Volume of playback.
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_