2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef MediaSession_h
27 #define MediaSession_h
29 #include <wtf/Noncopyable.h>
30 #include <wtf/text/WTFString.h>
34 class MediaSessionClient;
38 static std::unique_ptr<MediaSession> create(MediaSessionClient&);
40 MediaSession(MediaSessionClient&);
41 virtual ~MediaSession();
49 MediaType mediaType() const;
57 State state() const { return m_state; }
60 enum InterruptionType {
65 enum EndInterruptionFlags {
67 MayResumePlaying = 1 << 0,
69 void beginInterruption(InterruptionType);
70 void endInterruption(EndInterruptionFlags);
72 void applicationWillEnterForeground() const;
73 void applicationWillEnterBackground() const;
75 bool clientWillBeginPlayback();
76 bool clientWillPausePlayback();
80 #if ENABLE(PAGE_VISIBILITY_API)
81 void visibilityChanged();
85 double duration() const;
86 double currentTime() const;
88 enum RemoteControlCommandType {
93 TogglePlayPauseCommand,
94 BeginSeekingBackwardCommand,
95 EndSeekingBackwardCommand,
96 BeginSeekingForwardCommand,
97 EndSeekingForwardCommand,
99 bool canReceiveRemoteControlCommands() const;
100 void didReceiveRemoteControlCommand(RemoteControlCommandType);
103 MediaSessionClient& client() const { return m_client; }
106 #if ENABLE(PAGE_VISIBILITY_API)
107 void updateClientDataBuffering();
110 MediaSessionClient& m_client;
112 State m_stateToRestore;
113 bool m_notifyingClient;
116 class MediaSessionClient {
117 WTF_MAKE_NONCOPYABLE(MediaSessionClient);
119 MediaSessionClient() { }
121 virtual MediaSession::MediaType mediaType() const = 0;
122 virtual void resumePlayback() = 0;
123 virtual void pausePlayback() = 0;
125 virtual String mediaSessionTitle() const;
126 virtual double mediaSessionDuration() const;
127 virtual double mediaSessionCurrentTime() const;
129 virtual bool canReceiveRemoteControlCommands() const = 0;
130 virtual void didReceiveRemoteControlCommand(MediaSession::RemoteControlCommandType) = 0;
132 virtual void setShouldBufferData(bool) { }
133 virtual bool elementIsHidden() const { return false; }
135 virtual bool overrideBackgroundPlaybackRestriction() const = 0;
138 virtual ~MediaSessionClient() { }
143 #endif // MediaSession_h