2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Streamers\PHPStreamer;
|
2015-12-16 15:42:11 +00:00
|
|
|
use App\Http\Streamers\XAccelRedirectStreamer;
|
2015-12-16 16:15:20 +00:00
|
|
|
use App\Http\Streamers\XSendFileStreamer;
|
2015-12-13 04:42:28 +00:00
|
|
|
use App\Models\Song;
|
|
|
|
|
|
|
|
class SongController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Play a song.
|
|
|
|
* As of current Koel supports two streamer: x_sendfile and native PHP readfile.
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function play($id)
|
|
|
|
{
|
2015-12-16 15:42:11 +00:00
|
|
|
switch (env('STREAMING_METHOD')) {
|
|
|
|
case 'x-sendfile':
|
|
|
|
return (new XSendFileStreamer($id))->stream();
|
|
|
|
case 'x-accel-redirect':
|
|
|
|
return (new XAccelRedirectStreamer($id))->stream();
|
|
|
|
default:
|
|
|
|
return (new PHPStreamer($id))->stream();
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the lyrics of a song.
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function getLyrics($id)
|
|
|
|
{
|
|
|
|
return response()->json(Song::findOrFail($id)->lyrics);
|
|
|
|
}
|
|
|
|
}
|