2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Streamers\XSendFileStreamer;
|
|
|
|
use App\Http\Streamers\PHPStreamer;
|
|
|
|
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-14 04:32:29 +00:00
|
|
|
if (env('MOD_X_SENDFILE_ENABLED')) {
|
2015-12-13 04:42:28 +00:00
|
|
|
(new XSendFileStreamer($id))->stream();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(new PHPStreamer($id))->stream();
|
|
|
|
|
|
|
|
// Exit here to avoid accidentally sending extra content at the end of the file.
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the lyrics of a song.
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function getLyrics($id)
|
|
|
|
{
|
|
|
|
return response()->json(Song::findOrFail($id)->lyrics);
|
|
|
|
}
|
|
|
|
}
|