Discord.Addons.Music 0.1.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Discord.Addons.Music" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Discord.Addons.Music --version 0.1.0                
#r "nuget: Discord.Addons.Music, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Nuget Nuget contributionswelcome discord_invite

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

Contributing

Looking for a constructive feedback, feedback about best practices would really help me out.

Pull requests are very welcome,, Thanks!

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 824 4/9/2022
0.2.0 612 10/18/2021
0.1.1 483 10/1/2021
0.1.0 478 9/28/2021
0.0.3 681 12/9/2020
0.0.2 510 12/6/2020
0.0.1 582 12/6/2020