koel/app/Http/Controllers/PlayController.php

25 lines
686 B
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Http\Requests\SongPlayRequest;
use App\Models\Song;
use App\Models\User;
2024-02-24 07:28:49 +00:00
use App\Services\Streamer\Streamer;
use Illuminate\Contracts\Auth\Authenticatable;
class PlayController extends Controller
{
/** @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);
2024-02-24 07:28:49 +00:00
return (new Streamer(song: $song, config: [
'transcode' => (bool) $transcode,
'bit_rate' => $user->preferences->transcodeQuality,
2024-02-24 07:28:49 +00:00
'start_time' => (float) $request->time,
]))->stream();
}
}