1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 import "media/mojo/mojom/media_types.mojom";
8 import "mojo/public/mojom/base/time.mojom";
9 import "services/media_session/public/mojom/media_session.mojom";
10 import "ui/gfx/geometry/mojom/geometry.mojom";
12 // Implemented by HTMLMediaElement in the renderer process to allow the
13 // browser to control media playback.
14 interface MediaPlayer {
15 // Requests the media player to start or resume media playback.
18 // Requests the media player to pause media playback.
19 RequestPause(bool triggered_by_user);
21 // Requests the media player to move forward the media playback position.
22 RequestSeekForward(mojo_base.mojom.TimeDelta seek_time);
24 // Requests the media player to move backward the media playback position.
25 RequestSeekBackward(mojo_base.mojom.TimeDelta seek_time);
27 // Requests the media player to move to a specific time.
28 RequestSeekTo(mojo_base.mojom.TimeDelta seek_time);
30 // Requests the media player to enter the Picture-in-Picture mode.
31 RequestEnterPictureInPicture();
33 // Requests the media player to mute or unmute.
34 RequestMute(bool mute);
36 // Set the volume multiplier to control audio ducking.
37 // Output volume should be set to |player_volume| * |multiplier|. The range
38 // of |multiplier| is [0, 1], where 1 indicates normal (non-ducked) playback.
39 SetVolumeMultiplier(double multiplier);
41 // Set the player as the persistent video. Persistent video should hide its
42 // controls and go fullscreen.
43 SetPersistentState(bool persistent);
45 // Notify the player that it is now eligible to start recording power
46 // measurements if |state| is true, else it is no longer eligible.
47 SetPowerExperimentState(bool enabled);
49 // Set the media player sink id to |sink_id|.
50 SetAudioSinkId(string sink_id);
52 // Suspends the media player when the host frame is closed.
53 SuspendForFrameClosed();
55 // Request the media player to start Media Remoting when there are available
57 RequestMediaRemoting();
60 // Implemented by the MediaWebContentsObserver. The remote lives in the renderer
61 // process and the receiver lives in the browser process.
62 interface MediaPlayerObserverClient {
63 // Gets a flag indicating whether media has been played before.
64 GetHasPlayedBefore() => (bool has_played_before);
67 // Implemented by MediaWebContentsObserver::MediaPlayerObserverHostImpl in the
69 interface MediaPlayerObserver {
70 // Notifies that the media player started playing content.
73 // Notifies that the media player stopped playing content,
74 // indicating in |stream_ended| if playback has reached the end of the stream.
75 OnMediaPaused(bool stream_ended);
77 // Notifies that the muted status of the media player has changed.
78 OnMutedStatusChanged(bool muted);
80 // Notifies that the media metadata of the media player has changed, along
81 // with the kind of tracks the media player has, and the type of content.
82 OnMediaMetadataChanged(
83 bool has_audio, bool has_video, MediaContentType content_type);
85 // Notifies the browser process that the media playback position has changed,
86 // and reports the new current position via |media_position|.
87 OnMediaPositionStateChanged(media_session.mojom.MediaPosition media_position);
89 // Notifies that the player has entered fullscreen.
90 // This does not differentiate native controls fullscreen and custom controls
91 // fullscreen. |status| is used by MediaWebContentsObserver to trigger
92 // automatically Picture-in-Picture for fullscreen videos.
93 OnMediaEffectivelyFullscreenChanged(FullscreenVideoStatus status);
95 // Notifies that the size of the media player has changed.
96 OnMediaSizeChanged(gfx.mojom.Size size);
98 // Notifies the browser process of PictureinPicture playback's availability.
99 OnPictureInPictureAvailabilityChanged(bool available);
101 // Notifies that the audio output sink has changed.
102 OnAudioOutputSinkChanged(string hashed_device_id);
104 // Notifies that the playback starts/stops using AudioService.
105 OnUseAudioServiceChanged(bool uses_audio_service);
107 // Notifies the browser process that the ability to switch audio output
108 // devices for the associated media player has been disabled.
109 OnAudioOutputSinkChangingDisabled();
111 // Notifies that the RemotePlayback metadata of the media player has changed.
112 OnRemotePlaybackMetadataChange(media_session.mojom.RemotePlaybackMetadata
113 remote_playback_metadata);
116 // Implemented by MediaWebContentsObserver::MediaPlayerHostImpl in the browser
118 interface MediaPlayerHost {
119 // Sends a message to the browser notifying the render frame associated to the
120 // document owning the HTMLMediaElement that a new MediaPlayer is available,
121 // passing a pending remote (i.e. |player_remote|) that will be used in the
122 // browser process to establish a channel with the HTMLMediaElement.
123 // |observer| starts observing the MediaPlayer as soon as the player is
125 OnMediaPlayerAdded(pending_associated_remote<MediaPlayer> player_remote,
126 pending_associated_receiver<MediaPlayerObserver> observer,