尝试从 youtube 视频流式传输音频时,DiscordJS v13 AudioPlayer 卡在缓冲上
Posted
技术标签:
【中文标题】尝试从 youtube 视频流式传输音频时,DiscordJS v13 AudioPlayer 卡在缓冲上【英文标题】:DiscordJS v13 AudioPlayer is stuck on buffering when trying to stream audio from a youtube video 【发布时间】:2021-11-11 01:13:05 【问题描述】:这是迄今为止我的不和谐音乐机器人的代码。我相信该机器人具有适当的权限,并且能够加入调用“!play”命令的人的语音频道。我遇到的问题是我似乎无法弄清楚为什么音频流卡在“缓冲”状态。文档指出“缓冲”状态应该通过或失败,但它似乎被卡住了。
client.on("messageCreate", async message =>
if (message.content.slice(0, 6) == "!play ")
// check input to see if it is a youtube URL
let input = message.content.slice(6);
if (isYoutubeUrl(input))
url = input;
else
formatInput(input);
url = await searchVideo(searchTerm);
if (message.member.voice.channelId !== null)
const permissions = message.member.voice.channel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK"))
return message.channel.send(
"I need the permissions to join and speak in your voice channel!"
);
const connection = joinVoiceChannel(
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
)
const stream = await ytdl(url, filter:'audioonly' );
const player = createAudioPlayer();
var resource = createAudioResource(stream, seek: 0, volume: 1 );
player.play(resource);
connection.subscribe(player);
else
message.reply("You need to be in a voice channel to play music!");
)
这是我控制台记录播放器本身时出现的情况
<ref *1> AudioPlayer
_events: [Object: null prototype] ,
_eventsCount: 0,
_maxListeners: undefined,
subscribers: [
PlayerSubscription
connection: [VoiceConnection],
player: [Circular *1]
],
_state:
status: 'buffering',
resource: AudioResource
playbackDuration: 0,
started: false,
silenceRemaining: -1,
edges: [Array],
playStream: [OggDemuxer],
metadata: null,
silencePaddingFrames: 5,
audioPlayer: [Circular *1]
,
onReadableCallback: [Function: onReadableCallback],
onFailureCallback: [Function: onFailureCallback],
onStreamError: [Function: onStreamError]
,
behaviors: noSubscriber: 'pause', maxMissedFrames: 5 ,
debug: [Function (anonymous)],
[Symbol(kCapture)]: false
【问题讨论】:
你怎么知道它卡在缓冲上?如果您调试了代码,请将调试日志附加到您的问题中,因为我们无法充分判断和回答 刚刚更新,谢谢提醒。 【参考方案1】:事实证明,流不是问题所在。我只需要使用“@discordjs/voice”包中的“getVoiceConnection”组件并将流广播到该连接。
【讨论】:
以上是关于尝试从 youtube 视频流式传输音频时,DiscordJS v13 AudioPlayer 卡在缓冲上的主要内容,如果未能解决你的问题,请参考以下文章
使用url从python流传输youtube音频而无需下载python
如何在我的应用程序上仅流式传输来自 youtube 视频的音频数据?
是否可以从 USB 摄像头流式传输视频和从移动麦克风传输音频以在 android 中进行 RTMP 流式传输