ahora reproduce canciones

This commit is contained in:
2025-03-31 16:50:45 -03:00
parent b8a4cdaa6a
commit 74e0463393
4 changed files with 214 additions and 30 deletions

View File

@@ -72,11 +72,26 @@ class SongController extends Controller
return response()->noContent(200);
}
/**
* @return void
* @param mixed $id
* @param int $id
*/
public function stream($id):void
public function stream($id)
{
$song = Song::find($id);
// Stream specified song
$this->authorize('view', $song);
if ($song && Storage::exists($song->path)) {
$file = Storage::path($song->path);
return response()->stream(function () use ($file) {
$stream = fopen($file, 'rb');
fpassthru($stream);
fclose($stream);
}, 200, [
'Content-Type' => 'audio/mpeg',
'Content-Disposition' => 'inline; filename="' . $file . '"',
'Accept-Ranges' => 'bytes',
]);
}
}
}