2020-09-07 20:43:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\SongPlayRequest;
|
|
|
|
use App\Models\Song;
|
2024-09-03 14:51:23 +00:00
|
|
|
use App\Models\User;
|
2024-02-24 07:28:49 +00:00
|
|
|
use App\Services\Streamer\Streamer;
|
2024-09-03 14:51:23 +00:00
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
2020-09-07 20:43:23 +00:00
|
|
|
|
|
|
|
class PlayController extends Controller
|
|
|
|
{
|
2024-09-03 14:51:23 +00:00
|
|
|
/** @param User $user */
|
|
|
|
public function __invoke(Authenticatable $user, SongPlayRequest $request, Song $song, ?bool $transcode = null)
|
2024-02-24 07:28:49 +00:00
|
|
|
{
|
2024-01-09 11:53:35 +00:00
|
|
|
$this->authorize('access', $song);
|
2020-09-07 20:43:23 +00:00
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
return (new Streamer(song: $song, config: [
|
|
|
|
'transcode' => (bool) $transcode,
|
2024-09-03 14:51:23 +00:00
|
|
|
'bit_rate' => $user->preferences->transcodeQuality,
|
2024-02-24 07:28:49 +00:00
|
|
|
'start_time' => (float) $request->time,
|
|
|
|
]))->stream();
|
2020-09-07 20:43:23 +00:00
|
|
|
}
|
|
|
|
}
|