return index of the audio channel instead of the channel itself
this is more useful because playing/stopping can be done on a specific channel more easily by specifying a channel index. and the index can obviously also be used to get the channel itself when/if needed, but it's not super convenient to get the index of a channel when you only have the channel itself
This commit is contained in:
parent
06d3d927fe
commit
cbfd66d42e
|
@ -205,13 +205,13 @@ impl AudioDevice {
|
||||||
&mut self,
|
&mut self,
|
||||||
buffer: &AudioBuffer,
|
buffer: &AudioBuffer,
|
||||||
loops: bool,
|
loops: bool,
|
||||||
) -> Result<Option<&mut AudioChannel>, AudioDeviceError> {
|
) -> Result<Option<usize>, AudioDeviceError> {
|
||||||
if *buffer.spec() != self.spec {
|
if *buffer.spec() != self.spec {
|
||||||
Err(AudioDeviceError::AudioSpecMismatch)
|
Err(AudioDeviceError::AudioSpecMismatch)
|
||||||
} else {
|
} else {
|
||||||
if let Some(channel) = self.stopped_channels_iter_mut().next() {
|
if let Some((index, channel)) = self.stopped_channels_iter_mut().enumerate().next() {
|
||||||
channel.play_buffer(buffer, loops);
|
channel.play_buffer(buffer, loops);
|
||||||
Ok(Some(channel))
|
Ok(Some(index))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -238,10 +238,10 @@ impl AudioDevice {
|
||||||
&mut self,
|
&mut self,
|
||||||
generator: Box<dyn AudioGenerator>,
|
generator: Box<dyn AudioGenerator>,
|
||||||
loops: bool,
|
loops: bool,
|
||||||
) -> Result<Option<&mut AudioChannel>, AudioDeviceError> {
|
) -> Result<Option<usize>, AudioDeviceError> {
|
||||||
if let Some(channel) = self.stopped_channels_iter_mut().next() {
|
if let Some((index, channel)) = self.stopped_channels_iter_mut().enumerate().next() {
|
||||||
channel.play_generator(generator, loops);
|
channel.play_generator(generator, loops);
|
||||||
Ok(Some(channel))
|
Ok(Some(index))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue