IAudioClient.StreamCreated is not called
See original GitHub issueConsole.WriteLine("Action was called");
IAudioClient client = await channel.ConnectAsync();
client.StreamCreated += async (ulong id, AudioInStream stream) => {
Console.WriteLine("StreamCreated was called");
await Task.Delay(recordingTime);
await channel.DisconnectAsync();
stream.CopyTo(mem);
doneListening = true;
};
Executing this code results in the following Console Output:
Action was called
14:03:50 Audio #1 Connecting
14:03:50 Audio #1 Unknown OpCode (Hello)
14:03:51 Audio #1 Connected
So StreamCreated was never called. Is receiving audio currently not supported? I couldn’t find any example code for this use case.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
IAudioClient::Start method (audioclient.h) - Win32
The audio stream is configured to use event-driven buffering, but the caller has not called IAudioClient::SetEventHandle to set the event ...
Read more >StreamEvent - OpenTok.js Vonage Video API Developer
StreamEvent is an event that can have the type "streamCreated" or "streamDestroyed". These events are dispatched by the Session object when another client ......
Read more >streamCreated not fired for existing participants - OpenVidu
I'm not receiving a streamCreated event for participants already connected so only older participants can see newer ones and not vice versa.
Read more >I get an error while trying to call IAudioClient::GetService()
I get these errors when I'm trying to compile the program: image. I can get rid of error LNK2001 by using __uuidof(IChannelAudioVolume) ...
Read more >C# (CSharp) IAudioClient Examples
These are the top rated real world C# (CSharp) examples of IAudioClient extracted from open ... StreamCreated += VoiceChannelAudioStreamCreated; client.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Aside from the issue of sending audio once in order to receive audio, there is another issue preventing StreamCreated from being called.
You will notice that StreamCreated does get called if, during the recording part of your code, a new user joins the voice channel (a stream gets created for this user). (you can also do this by you, the user, leaving the voice channel and rejoining after the bot has joined).
I conclude that StreamCreated is getting called, but it’s getting called before ConnectAsync() returns - StreamCreated is called by an internal method of the API triggered by the VOICE_STATE_UPDATED message being received from the discord api. This message is received before the channel finishes ConnectAsync(); that is, before you ever have access to the IAudioClient in order to add a StreamCreated event handler.
This is an oversight/bug of Discord.Net. There is currently no way to gain access to the AudioInStreams of users that were already connected to the voice channel that your bot joins, because there’s no way to add a StreamCreated event handler before these users’ streams are created (since ConnectAsync has not yet completed, and these users’ streams are created during ConnectAsync). You can only get access to AudioInStreams once users join the channel after your bot joins.
As a third option, how about an additional optional parameter in
ConnectAsync
which is a function that runs after the object is created, but before any events are processed? Something like this:This way, the event handlers are not subscribed too late and most existing code using these events will be very easy to migrate. It’s also not a breaking change to any code (as the event handlers would still exist).
Edit: I will be happy to implement this and submit a PR, if this approach is ok?