// Copyright (c) Arlo Godfrey. All Rights Reserved. // Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms. // See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information. using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using OwlCore.Events; using StrixMusic.Sdk.AppModels; using StrixMusic.Sdk.BaseModels; using StrixMusic.Sdk.CoreModels; namespace StrixMusic.Sdk.MediaPlayback { /// /// Manages an internal queue, handles playback, and delegates playback commands to an . /// public interface IPlaybackHandlerService : IAudioPlayerBase, IDisposable { /// /// Registers an to be used for actual local audio playback when a track from a certain core is played. /// /// The player that will be used for local playback by cores with a matching . /// A core instance ID to associate this audio player with. void RegisterAudioPlayer(IAudioPlayerService audioPlayer, string instanceId); /// /// Gets or sets the device which is being currently being used for playback, if any. /// public IDevice? ActiveDevice { get; set; } /// /// Gets a device which represents all local playback done by this . /// public IDevice LocalDevice { get; } /// /// The items that should be played next. /// IReadOnlyList NextItems { get; } /// /// Items that precede the currently playing item. Used to go to the previous track in the playback context. /// IReadOnlyCollection PreviousItems { get; } /// /// The currently playing item. /// PlaybackItem? CurrentItem { get; } /// /// The collection which the is playing from. /// IPlayableBase? CurrentItemContext { get; } /// /// True if the player is using a shuffled track list. /// bool ShuffleState { get; } /// RepeatState RepeatState { get; } /// /// Loads the given track collection into the play queue and plays the given track. /// /// The track to play. /// The actual playback context. /// The complete track collection that belongs to. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(ITrack track, ITrackCollection trackCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given track collection into the play queue and plays the first track. /// /// The actual playback context. /// The tracks to use in the queue. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(ITrackCollection trackCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given album collection into the play queue and plays the first track of the provided . /// /// The album item to play. /// The complete album collection that belongs to. /// The actual playback context. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(IAlbumCollectionItem albumCollectionItem, IAlbumCollection albumCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given playlist collection into the play queue and plays the given track. /// /// The track to play. /// The complete playlist collection that belongs to. /// The actual playback context. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(IPlaylistCollectionItem playlistCollectionItem, IPlaylistCollection playlistCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given track collection into the play queue and plays the first track. /// /// The actual playback context. /// The albums to use in the queue. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(IAlbumCollection albumCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given artist collection into the play queue and plays the given track. /// /// The album collection to play. /// The playback context. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(IArtistCollection artistCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given playlist collection into the play queue and plays the given track. /// /// The playlist collection to play. /// The actual playback context. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(IPlaylistCollection playlistCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Loads the given track collection into the play queue and plays the first track. /// /// The actual playback context. /// The artist item to play. /// The complete artist collection that belongs to. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayAsync(IArtistCollectionItem artistCollectionItem, IArtistCollection artistCollection, IPlayableBase context, CancellationToken cancellationToken = default); /// /// Plays a specific media from . /// /// The index of an item in . /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayFromNext(int queueIndex, CancellationToken cancellationToken = default); /// /// Plays a specific media from . /// /// The index of an item in . /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PlayFromPrevious(int queueIndex, CancellationToken cancellationToken = default); /// /// Advances to the next track. If there is no next track, playback is paused. /// /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task NextAsync(CancellationToken cancellationToken = default); /// /// Goes to the previous track. /// /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task PreviousAsync(CancellationToken cancellationToken = default); /// /// Inserts an item into the . /// /// The index to insert the item at. /// The item to insert. void InsertNext(int index, PlaybackItem sourceConfig); /// /// Removes an item from the . /// /// The index to insert the item at. void RemoveNext(int index); /// /// Clears all items from . /// void ClearNext(); /// /// Adds an item to the top of . /// /// The item to insert. void PushPrevious(PlaybackItem sourceConfig); /// /// Removes and returns item from top of the stack. /// /// The index to insert the item at. /// The that was in the requested index. PlaybackItem PopPrevious(int index); /// /// Clears all items from . /// void ClearPrevious(); /// /// Toggles shuffle on or off. /// /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task ToggleShuffleAsync(CancellationToken cancellationToken = default); /// /// Asks the device to toggle to the next repeat state. /// /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task ToggleRepeatAsync(CancellationToken cancellationToken = default); /// /// Sets the repeat state to a specific state. /// /// The new repeat state. /// A cancellation token that may be used to cancel the ongoing task. /// A representing the asynchronous operation. Task SetRepeatStateAsync(RepeatState state, CancellationToken cancellationToken = default); /// /// Fires when changes. /// event EventHandler ShuffleStateChanged; /// /// Fires when changes. /// event EventHandler RepeatStateChanged; /// /// Fires when the are updated. /// event CollectionChangedEventHandler? NextItemsChanged; /// /// Fires when the are updated. /// event CollectionChangedEventHandler? PreviousItemsChanged; /// /// Fires when the is changed. /// event EventHandler? CurrentItemChanged; /// /// Raised when a quantum of data is processed. /// event EventHandler? QuantumProcessed; } }