910e62b5创建于 1月15日历史提交
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module ash.focus_mode.mojom;

import "url/mojom/url.mojom";
import "mojo/public/mojom/base/time.mojom";

// Defines metadata and source URL for a track to play.
struct TrackDefinition {
  // The title of the track.
  string title;

  // The artist.
  string artist;

  // Where to get the thumbnail from.
  url.mojom.Url thumbnail_url;

  // Points to the actual audio data.
  url.mojom.Url media_url;

  // Indicates if playback reporting should be enabled.
  bool enable_playback_reporting;
};

// Implemented in Typescript and Used by Ash to control media playing.
interface MediaClient {
  // Notifies the WebUI that it should start playing the given track. If the
  // player is already playing a track, it will switch to the given track.
  StartPlay(TrackDefinition track);
};

// State of the media player.
enum PlaybackState {
  kPlaying,
  kPaused,
  kSwitchedToNext,
  kEnded,
  kNone,
};

// Defines player playback data. Values are from Typescript and used by Ash to
// report the playback status.
struct PlaybackData {
  // Playback state.
  PlaybackState state;

  // Track title.
  string title;

  // Track media url.
  url.mojom.Url url;

  // Client current time.
  mojo_base.mojom.JSTime client_current_time;

  // Playback start offset in seconds.
  int32 playback_start_offset;

  // Current media time in seconds.
  int32 media_time_current;

  // Start time in seconds of the period that the playback event covers.
  int32 media_start;

  // End time in seconds of the period that the playback event covers.
  int32 media_end;

  // Client start time.
  mojo_base.mojom.JSTime client_start_time;

  // Indicate if it's the initial playback, i.e. first playback after loading.
  bool initial_playback;
};

// Implemented in Ash and used by the WebUI side (Typescript) code to get track
// data from Ash.
interface TrackProvider {
  // Used by the player to ask for a track to play. When the player is created,
  // it will request the first track to play. When the track is finished, it
  // will request the next track.
  GetTrack() => (TrackDefinition track);

  // Used at startup to install its implementation of `MediaClient`.
  SetMediaClient(pending_remote<MediaClient> client);

  // Used by the player to report playback.
  ReportPlayback(PlaybackData data);

  // Used by the player to report an error.
  ReportPlayerError();
};