summaryrefslogtreecommitdiffstats
path: root/chromium/services/media_session/public/mojom/media_controller.mojom
blob: 2aa9af7b73828e8c16036c1a189cc47e1388b76b (plain)
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module media_session.mojom;

import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/media_session/public/mojom/media_session.mojom";

interface MediaControllerManager {
  // Creates a MediaController linked to a specific session with |request_id|.
  // This should match the |request_id| from the AudioFocusRequestState.
  CreateMediaControllerForSession(
      MediaController& request,
      mojo_base.mojom.UnguessableToken request_id);

  // Creates a MediaController linked to the active session. This will
  // automatically route commands to the correct session if the active session
  // changes. If there is no active session then commands will be no-ops.
  CreateActiveMediaController(MediaController& request);
};

// Controls a MediaSession. If the media session is not controllable then the
// commands will be no-ops.
interface MediaController {
  // Suspend the media session.
  Suspend();

  // Resume the media session.
  Resume();

  // Stop the media session.
  Stop();

  // This will either suspend or resume the media session based on the
  // playback state.
  ToggleSuspendResume();

  // Adds an observer that will forward events from the active media session.
  // If the active session changes then observers do not need to be readded.
  // Adding the observer will update the observer with the latest state.
  AddObserver(MediaControllerObserver observer);

  // Skip to the previous track. If there is no previous track then this will be
  // a no-op.
  PreviousTrack();

  // Skip to the next track. If there is no next track then this will be a
  // no-op.
  NextTrack();

  // Seek the media session. If the media cannot seek then this will be a
  // no-op. The |seek_time| is the time delta that the media will seek by and
  // supports both positive and negative values. This value cannot be zero.
  // The |kDefaultSeekTimeSeconds| provides a default value for seeking by a
  // few seconds.
  Seek(mojo_base.mojom.TimeDelta seek_time);
};

// The observer for observing media controller events. This is different to a
// MediaSessionObserver because a media controller can have nullable session
// info which will be null if it is not bound to a media session. This would
// be invalid for a media session because it must always have some state.
interface MediaControllerObserver {
  // Called when the state of the bound media session changes. If |info| is
  // empty then the controller is no longer bound to a media session.
  MediaSessionInfoChanged(MediaSessionInfo? info);

  // Called when the bound media session has changed metadata. If |metadata|
  // is null then it can be reset, e.g. the media that ws being played has
  // been stopped.
  MediaSessionMetadataChanged(MediaMetadata? metadata);

  // Called when the bound media session action list has changed. This tells
  // the observer which actions can be used to control the session.
  MediaSessionActionsChanged(array<MediaSessionAction> action);
};