pub struct Driver { /* private fields */ }
driver
only.Expand description
The control object for a Discord voice connection, handling connection, mixing, encoding, en/decryption, and event generation.
When compiled with the "builtin-queue"
feature, each driver includes a track queue
as a convenience to prevent the additional overhead of per-guild state management.
Implementations§
source§impl Driver
impl Driver
sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Creates a new voice driver.
This will create the core voice tasks in the background.
sourcepub fn connect(&mut self, info: ConnectionInfo) -> Connect ⓘ
pub fn connect(&mut self, info: ConnectionInfo) -> Connect ⓘ
Connects to a voice channel using the specified server.
This method instantly contacts the driver tasks, and its
does not need to be await
ed to start the actual connection.
sourcepub fn leave(&mut self)
pub fn leave(&mut self)
Leaves the current voice channel, disconnecting from it.
This does not forget settings, like whether to be self-deafened or self-muted.
sourcepub fn mute(&mut self, mute: bool)
pub fn mute(&mut self, mute: bool)
Sets whether the current connection is to be muted.
If there is no live voice connection, then this only acts as a settings update for future connections.
sourcepub fn is_mute(&self) -> bool
pub fn is_mute(&self) -> bool
Returns whether the driver is muted (i.e., processes audio internally but submits none).
sourcepub fn play_input(&mut self, input: Input) -> TrackHandle
pub fn play_input(&mut self, input: Input) -> TrackHandle
Plays audio from an input, returning a handle for further control.
sourcepub fn play_only_input(&mut self, input: Input) -> TrackHandle
pub fn play_only_input(&mut self, input: Input) -> TrackHandle
Plays audio from an input, returning a handle for further control.
Unlike Self::play_input
, this stops all other inputs attached
to the channel.
sourcepub fn play(&mut self, track: Track) -> TrackHandle
pub fn play(&mut self, track: Track) -> TrackHandle
Plays audio from a Track
object.
The main difference between this function and Self::play_input
is
that this allows for direct manipulation of the Track
object
before it is passed over to the voice and mixing contexts.
sourcepub fn play_only(&mut self, track: Track) -> TrackHandle
pub fn play_only(&mut self, track: Track) -> TrackHandle
Exclusively plays audio from a Track
object.
As in Self::play_only_input
, this stops all other sources attached to the
channel. Like Self::play
, however, this allows for direct manipulation of the
Track
object before it is passed over to the voice and mixing contexts.
sourcepub fn set_bitrate(&mut self, bitrate: Bitrate)
pub fn set_bitrate(&mut self, bitrate: Bitrate)
Sets the bitrate for encoding Opus packets sent along the channel being managed.
The default rate is 128 kbps.
Sensible values range between Bits(512)
and Bits(512_000)
bits per second.
Alternatively, Auto
and Max
remain available.
sourcepub fn set_config(&mut self, config: Config)
pub fn set_config(&mut self, config: Config)
Sets the configuration for this driver (and parent Call
, if applicable).
sourcepub fn add_global_event<F: EventHandler + 'static>(
&mut self,
event: Event,
action: F
)
pub fn add_global_event<F: EventHandler + 'static>( &mut self, event: Event, action: F )
Attach a global event handler to an audio context. Global events may receive
any EventContext
.
Global timing events will tick regardless of whether audio is playing,
so long as the bot is connected to a voice channel, and have no tracks.
TrackEvent
s will respond to all relevant tracks, giving some audio elements.
Users must ensure that no costly work or blocking occurs within the supplied function or closure. Taking excess time could prevent timely sending of packets, causing audio glitches and delays.
sourcepub fn remove_all_global_events(&mut self)
pub fn remove_all_global_events(&mut self)
Removes all global event handlers from an audio context.
source§impl Driver
impl Driver
sourcepub fn queue(&self) -> &TrackQueue
Available on crate feature builtin-queue
only.
pub fn queue(&self) -> &TrackQueue
builtin-queue
only.Returns a reference to this driver’s built-in queue.
Requires the "builtin-queue"
feature.
Queue additions should be made via Driver::enqueue
and
Driver::enqueue_input
.
sourcepub async fn enqueue_input(&mut self, input: Input) -> TrackHandle
Available on crate feature builtin-queue
only.
pub async fn enqueue_input(&mut self, input: Input) -> TrackHandle
builtin-queue
only.Adds an audio Input
to this driver’s built-in queue.
Requires the "builtin-queue"
feature.
sourcepub async fn enqueue(&mut self, track: Track) -> TrackHandle
Available on crate feature builtin-queue
only.
pub async fn enqueue(&mut self, track: Track) -> TrackHandle
builtin-queue
only.Adds an existing Track
to this driver’s built-in queue.
Requires the "builtin-queue"
feature.
sourcepub fn enqueue_with_preload(
&mut self,
track: Track,
preload_time: Option<Duration>
) -> TrackHandle
Available on crate feature builtin-queue
only.
pub fn enqueue_with_preload( &mut self, track: Track, preload_time: Option<Duration> ) -> TrackHandle
builtin-queue
only.Add an existing Track
to the queue, using a known time to preload the next track.
See TrackQueue::add_with_preload
for how preload_time
is used.
Requires the "builtin-queue"
feature.