mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 06:04:16 +00:00
queue: add crossbeam-channel
feature flag (#500)
This commit is contained in:
parent
8f949a81c8
commit
9674ea56cf
3 changed files with 15 additions and 4 deletions
|
@ -16,6 +16,7 @@ hound = { version = "3.3.1", optional = true }
|
|||
lewton = { version = "0.10", optional = true }
|
||||
minimp3 = { version = "0.5.0", optional = true }
|
||||
symphonia = { version = "0.5.2", optional = true, default-features = false }
|
||||
crossbeam-channel = { version = "0.5.8", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["flac", "vorbis", "wav", "mp3"]
|
||||
|
|
12
src/queue.rs
12
src/queue.rs
|
@ -1,13 +1,17 @@
|
|||
//! Queue that plays sounds one after the other.
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::source::{Empty, Source, Zero};
|
||||
use crate::Sample;
|
||||
|
||||
#[cfg(feature = "crossbeam-channel")]
|
||||
use crossbeam_channel::{unbounded as channel, Receiver, Sender};
|
||||
#[cfg(not(feature = "crossbeam-channel"))]
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
|
||||
/// Builds a new queue. It consists of an input and an output.
|
||||
///
|
||||
/// The input can be used to add sounds to the end of the queue, while the output implements
|
||||
|
@ -66,12 +70,14 @@ where
|
|||
/// Adds a new source to the end of the queue.
|
||||
///
|
||||
/// The `Receiver` will be signalled when the sound has finished playing.
|
||||
///
|
||||
/// Enable the feature flag `crossbeam-channel` in rodio to use a `crossbeam_channel::Receiver` instead.
|
||||
#[inline]
|
||||
pub fn append_with_signal<T>(&self, source: T) -> Receiver<()>
|
||||
where
|
||||
T: Source<Item = S> + Send + 'static,
|
||||
{
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let (tx, rx) = channel();
|
||||
self.next_sounds
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::Receiver;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(feature = "crossbeam-channel")]
|
||||
use crossbeam_channel::Receiver;
|
||||
#[cfg(not(feature = "crossbeam-channel"))]
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
use crate::stream::{OutputStreamHandle, PlayError};
|
||||
use crate::{queue, source::Done, Sample, Source};
|
||||
use cpal::FromSample;
|
||||
|
|
Loading…
Reference in a new issue