Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System.Threading.Tasks;
  2. using Discord;
  3. using Discord.Commands;
  4. using System.Diagnostics;
  5. using Discord.Audio;
  6. using System;
  7. using System.Runtime.InteropServices;
  8.  
  9.  
  10. public class SoundPlayer : ModuleBase<ICommandContext>
  11.  
  12.     {
  13.     [DllImport("libc")]
  14.     public static extern int system(string exec);
  15.     public static IAudioClient client;
  16.  
  17.  
  18.         private Process CreateStream(string url)
  19.         {
  20.         Process currentsong = new Process();
  21.         currentsong.StartInfo = new ProcessStartInfo
  22.         {
  23.             Arguments = Convert.ToString(system("youtube-dl -o - " + url + " | ffmpeg -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1 &"))
  24.  
  25.         };
  26.         currentsong.Start();
  27.         return currentsong;
  28.         }
  29.  
  30.  
  31.         [Command("play", RunMode = RunMode.Async)]
  32.         public async Task play(string url, IVoiceChannel channel = null)
  33.         {
  34.             var User = Context.User;
  35.             var Channel = Context.Channel;
  36.             channel = channel ?? (User as IGuildUser)?.VoiceChannel;
  37.             var audioClient = await channel.ConnectAsync();
  38.  
  39.             var output = CreateStream(url).StandardOutput.BaseStream;
  40.             var stream = audioClient.CreatePCMStream(AudioApplication.Music, 128 * 1024);
  41.            await output.CopyToAsync(stream);
  42.            await stream.FlushAsync().ConfigureAwait(false);
  43.         }
  44.  
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement