discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
1k stars 237 forks source link

PlayRawStream not working #985

Closed GrzegorzWalewski closed 1 year ago

GrzegorzWalewski commented 1 year ago

Environment

Describe the bug playRawStream() is not playing any songs, just silence

To Reproduce Steps to reproduce the behavior:

        $discord->joinVoiceChannel($channel)->then(function (VoiceClient $client) {
            $stream = new ReadableResourceStream(fopen('http://noisefm.ru:8000/play?icy=http','r'));
            $client->playRawStream($stream)->then(function () {
                echo "done\n";
            }, function ($e) {
                echo "failed to play song:\n";
            });
        }, function ($e) {
            echo "failed to join voice channel:\n";
        });

Expected behavior Bot joins channel and plays music, or throws any error

Additional context I resolved this issue, by editing src/Discord/Voice/VoiceClient.php: image to: image

Maybe it will help somebody. I spent 3 days on this(and lost some hair also). Maybe You can fix this in next release ;)

Peace!

key2peace commented 1 year ago

playRawStream expects as the name says a RAW pcm stream, not an icecast encoded aac/mp3 stream. I've made a small modification in #986 to have playFile accept urls, as files, then your solution should be like this:

$discord->joinVoiceChannel($channel)->then(function (VoiceClient $client) {
  $client->playFile('http://noisefm.ru:8000/play?icy=http')->then(function () {
    echo "done\n";
  }, function ($e) {
    echo "failed to play song:\n";
  });
}, function ($e) {
  echo "failed to join voice channel:\n";
});