Events: Add Play/Pause events.
Uses much of the existing machinery to add some more PlayMode state change events—all in all, a pretty simple change. Closes #29.
This commit is contained in:
@@ -70,8 +70,8 @@ pub(crate) async fn runner(_interconnect: Interconnect, evt_rx: Receiver<EventMe
|
|||||||
Mode(mode) => {
|
Mode(mode) => {
|
||||||
let old = state.playing;
|
let old = state.playing;
|
||||||
state.playing = mode;
|
state.playing = mode;
|
||||||
if old != mode && mode.is_done() {
|
if old != mode {
|
||||||
global.fire_track_event(TrackEvent::End, i);
|
global.fire_track_event(mode.as_track_event(), i);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Volume(vol) => {
|
Volume(vol) => {
|
||||||
|
|||||||
@@ -10,6 +10,14 @@
|
|||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum TrackEvent {
|
pub enum TrackEvent {
|
||||||
|
/// The attached track has resumed playing.
|
||||||
|
///
|
||||||
|
/// This event will not fire when a track first starts,
|
||||||
|
/// but will fire when a track changes from, e.g., paused to playing.
|
||||||
|
/// This is most relevant for queue users.
|
||||||
|
Play,
|
||||||
|
/// The attached track has been paused.
|
||||||
|
Pause,
|
||||||
/// The attached track has ended.
|
/// The attached track has ended.
|
||||||
End,
|
End,
|
||||||
/// The attached track has looped.
|
/// The attached track has looped.
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::events::TrackEvent;
|
||||||
|
|
||||||
/// Playback status of a track.
|
/// Playback status of a track.
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
@@ -29,6 +31,15 @@ impl PlayMode {
|
|||||||
state => state,
|
state => state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn as_track_event(self) -> TrackEvent {
|
||||||
|
use PlayMode::*;
|
||||||
|
match self {
|
||||||
|
Play => TrackEvent::Play,
|
||||||
|
Pause => TrackEvent::Pause,
|
||||||
|
Stop | End => TrackEvent::End,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlayMode {
|
impl Default for PlayMode {
|
||||||
|
|||||||
Reference in New Issue
Block a user