koel/app/Http/Controllers/API/SongController.php

43 lines
889 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
use App\Http\Streamers\PHPStreamer;
2015-12-14 13:22:39 +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)
{
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);
}
}