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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use std::sync::Arc;
use ringbuf::HeapProducer;
use crate::{tween::Tween, CommandError, PlaybackRate, Volume};
use super::{sound::Shared, Command, PlaybackState};
pub struct StaticSoundHandle {
pub(super) command_producer: HeapProducer<Command>,
pub(super) shared: Arc<Shared>,
}
impl StaticSoundHandle {
pub fn state(&self) -> PlaybackState {
self.shared.state()
}
pub fn position(&self) -> f64 {
self.shared.position()
}
pub fn set_volume(
&mut self,
volume: impl Into<Volume>,
tween: Tween,
) -> Result<(), CommandError> {
self.command_producer
.push(Command::SetVolume(volume.into(), tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn set_playback_rate(
&mut self,
playback_rate: impl Into<PlaybackRate>,
tween: Tween,
) -> Result<(), CommandError> {
self.command_producer
.push(Command::SetPlaybackRate(playback_rate.into(), tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn set_panning(&mut self, panning: f64, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::SetPanning(panning, tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn pause(&mut self, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::Pause(tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn resume(&mut self, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::Resume(tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn stop(&mut self, tween: Tween) -> Result<(), CommandError> {
self.command_producer
.push(Command::Stop(tween))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn seek_to(&mut self, position: f64) -> Result<(), CommandError> {
self.command_producer
.push(Command::SeekTo(position))
.map_err(|_| CommandError::CommandQueueFull)
}
pub fn seek_by(&mut self, amount: f64) -> Result<(), CommandError> {
self.command_producer
.push(Command::SeekBy(amount))
.map_err(|_| CommandError::CommandQueueFull)
}
}