Discord.Addons.Music
0.1.0
See the version list below for details.
dotnet add package Discord.Addons.Music --version 0.1.0
NuGet\Install-Package Discord.Addons.Music -Version 0.1.0
<PackageReference Include="Discord.Addons.Music" Version="0.1.0" />
paket add Discord.Addons.Music --version 0.1.0
#r "nuget: Discord.Addons.Music, 0.1.0"
// Install Discord.Addons.Music as a Cake Addin #addin nuget:?package=Discord.Addons.Music&version=0.1.0 // Install Discord.Addons.Music as a Cake Tool #tool nuget:?package=Discord.Addons.Music&version=0.1.0
Unofficial Discord.Net Addons for Audio
Audio player library for Discord.Net using FFmpeg and Youtube-dl
This project is still in development and not production ready
Requirements
Installation
NuGet
Getting started
This is a basic example on how to use AudioPlayer
.
// Initialize AudioPlayer
AudioPlayer audioPlayer = new AudioPlayer();
// Set player's audio client
// This is required for AudioPlayer to create an audio stream to Discord
SocketVoiceChannel voiceChannel = (Context.User as SocketGuildUser)?.VoiceChannel;
var audioClient = await voiceChannel.ConnectAsync();
audioPlayer.SetAudioClient(audioClient);
Playing an audio
To play an audio, we need to load an AudioTrack instance. To do this, we can use TrackLoader
class:
string query = "Tuturu Ringtone";
bool wellFormedUri = Uri.IsWellFormedUriString(query, UriKind.Absolute);
List<AudioTrack> tracks = await TrackLoader.LoadAudioTrack(query, fromUrl: wellFormedUri);
// Pick the first entry and use AudioPlayer.StartTrackAsync to play it
AudioTrack firstTrack = tracks.ElementAt(0);
player.StartTrackAsync(firstTrack, interrupt: true);
Handling Audio Event
AudioPlayer implements IAudioEvent and currently there are 3 audio events that can be subscribed:
- OnTrackStartAsync
- OnTrackEndAsync
- OnTrackErrorAsync
For example, a track scheduler:
public class TrackScheduler
{
public Queue<AudioTrack> SongQueue { get; set; }
private AudioPlayer player;
public TrackScheduler(AudioPlayer player)
{
SongQueue = new Queue<AudioTrack>();
this.player = player;
this.player.OnTrackStartAsync += OnTrackStartAsync;
this.player.OnTrackEndAsync += OnTrackEndAsync;
}
public void EnqueueAsync(AudioTrack track)
{
if (player.StartTrackAsync(track, interrupt: false) == false)
{
SongQueue.Enqueue(track);
}
}
public void NextTrack()
{
player.StartTrackAsync(SongQueue.Dequeue(), interrupt: true);
}
private Task OnTrackStartAsync(IAudioClient audioClient, IAudioSource track)
{
Console.WriteLine("Track start! " + track.Info.Title);
return Task.CompletedTask;
}
private Task OnTrackEndAsync(IAudioClient audioClient, IAudioSource track)
{
Console.WriteLine("Track end! " + track.Info.Title);
if (SongQueue.Count > 0)
{
NextTrack();
}
return Task.CompletedTask;
}
}
Note:
- AudioTrack is actually a PCM AudioSource
- Opus AudioSource is not yet supported
Contributions are very very welcome :]
Example Music Bot
- Example for guild state management and queue system, at ExampleMusicBot project
Contributing
Looking for a constructive feedback, feedback about best practices would really help me out.
Pull requests are very welcome,, Thanks!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Discord.Net.WebSocket (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.