// Copyright 2020 Ben Hills and the project contributors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:pinepods_mobile/entities/episode.dart'; import 'package:pinepods_mobile/entities/sleep.dart'; import 'package:pinepods_mobile/state/queue_event_state.dart'; import 'package:pinepods_mobile/state/transcript_state_event.dart'; import 'package:rxdart/rxdart.dart'; enum AudioState { none, buffering, starting, playing, pausing, stopped, error, } class PositionState { Duration position; late Duration length; late int percentage; Episode? episode; final bool buffering; PositionState({ required this.position, required this.length, required this.percentage, this.episode, this.buffering = false, }); PositionState.emptyState() : position = const Duration(seconds: 0), length = const Duration(seconds: 0), percentage = 0, buffering = false; } /// This class defines the audio playback options supported by Pinepods. /// /// The implementing classes will then handle the specifics for the platform we are running on. abstract class AudioPlayerService { /// Play a new episode, optionally resume at last save point. Future playEpisode({required Episode episode, bool resume = true}); /// Resume playing of current episode Future play(); /// Stop playing of current episode. Set update to false to stop /// playback without saving any episode or positional updates. Future stop(); /// Pause the current episode. Future pause(); /// Rewind the current episode by pre-set number of seconds. Future rewind(); /// Fast forward the current episode by pre-set number of seconds. Future fastForward(); /// Seek to the specified position within the current episode. Future seek({required int position}); /// Call when the app is resumed to re-establish the audio service. Future resume(); /// Add an episode to the playback queue Future addUpNextEpisode(Episode episode); /// Remove an episode from the playback queue if it exists Future removeUpNextEpisode(Episode episode); /// Remove an episode from the playback queue if it exists Future moveUpNextEpisode(Episode episode, int oldIndex, int newIndex); /// Empty the up next queue Future clearUpNext(); /// Call when the app is about to be suspended. Future suspend(); /// Call to set the playback speed. Future setPlaybackSpeed(double speed); /// Call to toggle trim silence. Future trimSilence(bool trim); /// Call to toggle trim silence. Future volumeBoost(bool boost); Future searchTranscript(String search); Future clearTranscript(); void sleep(Sleep sleep); Episode? nowPlaying; /// Event listeners Stream? playingState; ValueStream? playPosition; ValueStream? episodeEvent; Stream? transcriptEvent; Stream? playbackError; Stream? queueState; Stream? sleepStream; }