Input: Allow Restartable sources to be lazy
This change is made with queue users in mind. Since sources of this kind *know* how to (re)create themselves, they can avoid being created at all until needed. This also adds machinery to preload tracks *before* they are needed, for gapless playback on queues and so on. Queues make use of the event system to do this.
This commit is contained in:
@@ -35,7 +35,10 @@ use serenity::{
|
||||
};
|
||||
|
||||
use songbird::{
|
||||
input,
|
||||
input::{
|
||||
self,
|
||||
restartable::Restartable,
|
||||
},
|
||||
Event,
|
||||
EventContext,
|
||||
EventHandler as VoiceEventHandler,
|
||||
@@ -477,7 +480,10 @@ async fn queue(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
let source = match input::ytdl(&url).await {
|
||||
|
||||
// Here, we use lazy restartable sources to make sure that we don't pay
|
||||
// for decoding, playback on tracks which aren't actually live yet.
|
||||
let source = match Restartable::ytdl(url, true).await {
|
||||
Ok(source) => source,
|
||||
Err(why) => {
|
||||
println!("Err starting source: {:?}", why);
|
||||
@@ -488,7 +494,7 @@ async fn queue(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
},
|
||||
};
|
||||
|
||||
handler.enqueue_source(source);
|
||||
handler.enqueue_source(source.into());
|
||||
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
|
||||
@@ -183,7 +183,7 @@ async fn play(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
if let Ok(song) = Restartable::ytdl(msg.content.clone()).await {
|
||||
if let Ok(song) = Restartable::ytdl(msg.content.clone(), false).await {
|
||||
let input = Input::from(song);
|
||||
|
||||
let content = format!(
|
||||
|
||||
Reference in New Issue
Block a user