-
Notifications
You must be signed in to change notification settings - Fork 54
/
MediaControlKeysEvent.h
100 lines (83 loc) · 3.23 KB
/
MediaControlKeysEvent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSEVENT_H_
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSEVENT_H_
#include "mozilla/dom/MediaMetadata.h"
#include "mozilla/dom/MediaSessionBinding.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
/**
* MediaControlKeysEvent represents all possible control buttons in controller
* interface, no matter it's physical one, such as keyboard, headset, or a
* virtual one, such as the interface provided by Android MediaController.
* Note. keep this sync with `MediaControlKeysTestEvent` in ChromeUtils.webidl.
*/
enum class MediaControlKeysEvent : uint32_t {
ePlay,
ePause,
ePlayPause,
ePrevTrack,
eNextTrack,
eSeekBackward,
eSeekForward,
// Keep this the last element, or you have to modify the serialized structure
// in `MediaControlIPC.h` when you use other element as the last one.
eStop,
};
/**
* MediaControlKeysEventListener is a pure interface, which is used to monitor
* MediaControlKeysEvent, we can add it onto the MediaControlKeysEventSource,
* and then everytime when the media key events occur, `OnKeyPressed` will be
* called so that we can do related handling.
*/
class MediaControlKeysEventListener {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
MediaControlKeysEventListener() = default;
virtual void OnKeyPressed(MediaControlKeysEvent aKeyEvent) = 0;
protected:
virtual ~MediaControlKeysEventListener() = default;
};
/**
* MediaControlKeysHandler is used to operate media controller by corresponding
* received media control key events.
*/
class MediaControlKeysHandler final : public MediaControlKeysEventListener {
public:
NS_INLINE_DECL_REFCOUNTING(MediaControlKeysHandler, override)
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override;
private:
virtual ~MediaControlKeysHandler() = default;
};
/**
* MediaControlKeysEventSource is an abstract class which is used to implement
* transporting media control keys event to all its listeners when media keys
* event happens.
*/
class MediaControlKeysEventSource {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
MediaControlKeysEventSource();
virtual void AddListener(MediaControlKeysEventListener* aListener);
virtual void RemoveListener(MediaControlKeysEventListener* aListener);
size_t GetListenersNum() const;
// Return true if the initialization of the source succeeds, and inherited
// sources should implement this method to handle the initialization fails.
virtual bool Open() = 0;
virtual void Close();
virtual bool IsOpened() const = 0;
virtual void SetPlaybackState(MediaSessionPlaybackState aState);
virtual MediaSessionPlaybackState GetPlaybackState() const;
// Override this method if the event source needs to handle the metadata.
virtual void SetMediaMetadata(const MediaMetadataBase& aMetadata) {}
protected:
virtual ~MediaControlKeysEventSource() = default;
nsTArray<RefPtr<MediaControlKeysEventListener>> mListeners;
MediaSessionPlaybackState mPlaybackState;
};
} // namespace dom
} // namespace mozilla
#endif