mirror of
https://github.com/koel/koel
synced 2024-11-28 15:00:42 +00:00
Refactor
This commit is contained in:
parent
089283b04c
commit
1f6d272f39
1 changed files with 29 additions and 22 deletions
|
@ -14,43 +14,50 @@ use YouTube;
|
|||
class SongController extends Controller
|
||||
{
|
||||
/**
|
||||
* Play a song.
|
||||
* Play/stream a song.
|
||||
*
|
||||
* @link https://github.com/phanan/koel/wiki#streaming-music
|
||||
*
|
||||
* @param Song $song
|
||||
* @param null|bool $transcode
|
||||
* @param null|int $bitrate
|
||||
* @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.
|
||||
*/
|
||||
public function play(Song $song, $transcode = null, $bitrate = null)
|
||||
public function play(Song $song, $transcode = null, $bitRate = null)
|
||||
{
|
||||
if (null === $bitrate) {
|
||||
$bitrate = env('OUTPUT_BIT_RATE', 128);
|
||||
}
|
||||
|
||||
if ($song->s3_params) {
|
||||
return (new S3Streamer($song))->stream();
|
||||
}
|
||||
|
||||
// If transcode parameter isn't passed, the default is to only transcode flac
|
||||
if (null === $transcode && ends_with(mime_content_type($song->path), 'flac')) {
|
||||
// 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;
|
||||
} else {
|
||||
$transcode = (bool) $transcode;
|
||||
}
|
||||
|
||||
$streamer = null;
|
||||
|
||||
if ($transcode) {
|
||||
return (new TranscodingStreamer($song, $bitrate, request()->input('time', 0)))->stream();
|
||||
$streamer = new TranscodingStreamer(
|
||||
$song,
|
||||
$bitRate ? $bitRate : env('OUTPUT_BIT_RATE', 128),
|
||||
request()->input('time', 0)
|
||||
);
|
||||
} else {
|
||||
switch (env('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;
|
||||
}
|
||||
}
|
||||
|
||||
switch (env('STREAMING_METHOD')) {
|
||||
case 'x-sendfile':
|
||||
return (new XSendFileStreamer($song))->stream();
|
||||
case 'x-accel-redirect':
|
||||
return (new XAccelRedirectStreamer($song))->stream();
|
||||
default:
|
||||
return (new PHPStreamer($song))->stream();
|
||||
}
|
||||
$streamer->stream();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue