Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having problems with ffmpeg and youtube-dl trying to stream music- c# #13785

Closed
kakdila opened this issue Jul 31, 2017 · 1 comment
Closed

having problems with ffmpeg and youtube-dl trying to stream music- c# #13785

kakdila opened this issue Jul 31, 2017 · 1 comment
Labels

Comments

@kakdila
Copy link

@kakdila kakdila commented Jul 31, 2017

im making a discord music bot that streams from youtube using youtube-dl and ffmpeg.
the issue is that after i play one song and the second one starts to play the song stops and writes https://prnt.sc/g2gh8j. im quite new to ffmpeg so i dont realy know how to handle it
i have this command
` if (Program.current_s == null && Program.audioClient != null)
{
SendAsync(Program.audioClient, choice);
Program.playlist = new List();
Program.playlist_nammes = new List();
Program.playlist_nammes.Add(title);
delete_messages(1);
await ReplyAsync("now playing: " + title);
await Task.Delay(TimeSpan.FromSeconds(Program.duration[0] + 3));
Program.output.Close();
Program.current_s.Kill();
}

        else if (Program.current_s.HasExited == false)
        {
            Program.playlist.Add(choice);
            Program.playlist_nammes.Add(title);
            await ReplyAsync("added to playlist " + title);
            Console.WriteLine(title + " added to playlist");
        }` `

`private Process CreateStream(string path)
{

        Program.current_s = new Process();
        Program.current_s.Exited += new EventHandler(WhenSongEnds);
        Program.current_s.StartInfo = new ProcessStartInfo
        {
            FileName = "cmd.exe",
            Arguments = $"/C youtube-dl.exe -o - {path} | ffmpeg -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = false
        };
        Program.current_s.EnableRaisingEvents = true;
        Console.WriteLine("                     ffmpeg is ready");
        Program.current_s.Start();
        return Program.current_s;



    }

    private async Task SendAsync(IAudioClient client, string path)
    {

        Program.output = CreateStream(path).StandardOutput.BaseStream;
        var discord = client.CreatePCMStream(AudioApplication.Music, 128 * 1024);
        Program.output.CopyToAsync(discord);
        discord.FlushAsync().ConfigureAwait(false);

    }`

and this exited event
` private async void WhenSongEnds(object sender, EventArgs e)
{
Console.WriteLine("done with song");

        Program.playlist_nammes.Remove(Program.playlist_nammes[0]);
        Program.duration.Remove(Program.duration[0]);

        if (Program.playlist.Count > 0)
        {
            SendAsync(Program.audioClient, Program.playlist[0]);
            Program.playlist.Remove(Program.playlist[0]);
            Context.Channel.SendMessageAsync("Now playing" + Program.playlist_nammes[0]);
            await Task.Delay(TimeSpan.FromSeconds(Program.duration[0] + 3));
            Program.output.Close();
            Program.current_s.Kill();
        }
        else
            Program.current_s = null;

`

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jul 31, 2017

Carefully read new issue template and provide all requested information.

@dstftw dstftw closed this Jul 31, 2017
@dstftw dstftw added the incomplete label Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.