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

42 lines
971 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-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.
2015-12-16 17:24:33 +00:00
* @link https://github.com/phanan/koel/wiki#streaming-music
2015-12-13 04:42:28 +00:00
*
* @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);
}
}