Inheritance: extends Streamer, implements App\Http\Streamers\StreamerInterface
Example #1
0
 /**
  * Play/stream a song.
  *
  * @link https://github.com/phanan/koel/wiki#streaming-music
  *
  * @param Song      $song      The song to stream.
  * @param null|bool $transcode Whether to force transcoding the song.
  *                             If this is omitted, by default Koel will transcode FLAC.
  * @param null|int  $bitRate   The target bit rate to transcode, defaults to OUTPUT_BIT_RATE.
  *                             Only taken into account if $transcode is truthy.
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function play(Song $song, $transcode = null, $bitRate = null)
 {
     if ($song->s3_params) {
         return (new S3Streamer($song))->stream();
     }
     // If `transcode` parameter isn't passed, the default is to only transcode FLAC.
     if ($transcode === null && ends_with(mime_content_type($song->path), 'flac')) {
         $transcode = true;
     }
     $streamer = null;
     if ($transcode) {
         $streamer = new TranscodingStreamer($song, $bitRate ?: config('koel.streaming.bitrate'), request()->input('time', 0));
     } else {
         switch (config('koel.streaming.method')) {
             case 'x-sendfile':
                 $streamer = new XSendFileStreamer($song);
                 break;
             case 'x-accel-redirect':
                 $streamer = new XAccelRedirectStreamer($song);
                 break;
             default:
                 $streamer = new PHPStreamer($song);
                 break;
         }
     }
     $streamer->stream();
 }