| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ | |
| 6 #define CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ | |
| 7 | |
| 8 #include "base/time/time.h" | |
| 9 #include "content/browser/media/android/media_session_observer.h" | |
| 10 #include "content/common/content_export.h" | |
| 11 #include "content/public/browser/web_contents_observer.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 class MediaSession; | |
| 16 class MediaWebContentsObserver; | |
| 17 | |
| 18 // Helper class for controlling a single player's MediaSession instance. Sends | |
| 19 // browser side MediaSession commands back to a player hosted in the renderer | |
| 20 // process. | |
| 21 class CONTENT_EXPORT MediaSessionController : public MediaSessionObserver { | |
| 22 public: | |
| 23 MediaSessionController(const WebContentsObserver::MediaPlayerId& id, | |
| 24 MediaWebContentsObserver* media_web_contents_observer); | |
| 25 ~MediaSessionController() override; | |
| 26 | |
| 27 // Minimum duration of content for a MediaSession instance to be created. | |
| 28 enum { kMinimumDurationForContentSecs = 5 }; | |
| 29 | |
| 30 // Clients must call this after construction and destroy the controller if it | |
| 31 // returns false. May be called more than once; does nothing if none of the | |
| 32 // input parameters have changed since the last call. | |
| 33 // | |
| 34 // Note: Once a session has been initialized with |has_audio| as true, all | |
| 35 // future calls to Initialize() will retain this flag. | |
| 36 // TODO(dalecurtis): Delete sticky audio once we're no longer using WMPA and | |
| 37 // the BrowserMediaPlayerManagers. Tracked by http://crbug.com/580626 | |
| 38 bool Initialize(bool has_audio, bool is_remote, base::TimeDelta duration); | |
| 39 | |
| 40 // Must be called when a pause occurs on the renderer side media player; keeps | |
| 41 // the MediaSession instance in sync with renderer side behavior. | |
| 42 void OnPlaybackPaused(); | |
| 43 | |
| 44 // MediaSessionObserver implementation. | |
| 45 void OnSuspend(int player_id) override; | |
| 46 void OnResume(int player_id) override; | |
| 47 void OnSetVolumeMultiplier(int player_id, double volume_multiplier) override; | |
| 48 | |
| 49 // Test helpers. | |
| 50 int get_player_id_for_testing() const { return player_id_; } | |
| 51 | |
| 52 private: | |
| 53 const WebContentsObserver::MediaPlayerId id_; | |
| 54 | |
| 55 // Non-owned pointer; |media_web_contents_observer_| is the owner of |this|. | |
| 56 MediaWebContentsObserver* const media_web_contents_observer_; | |
| 57 | |
| 58 // Non-owned pointer; lifetime is the same as |media_web_contents_observer_|. | |
| 59 MediaSession* const media_session_; | |
| 60 | |
| 61 int player_id_ = 0; | |
| 62 bool has_session_ = false; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(MediaSessionController); | |
| 65 }; | |
| 66 | |
| 67 } // namespace content | |
| 68 | |
| 69 #endif // CONTENT_BROWSER_MEDIA_ANDROID_MEDIA_SESSION_CONTROLLER_H_ | |
| OLD | NEW |