koel/app/Services/Streamers/Streamer.php

34 lines
819 B
PHP
Raw Normal View History

2015-12-13 12:42:28 +08:00
<?php
2017-04-20 19:20:32 +08:00
namespace App\Services\Streamers;
2015-12-13 12:42:28 +08:00
use App\Models\Song;
2016-02-02 16:01:47 +08:00
class Streamer
2015-12-13 12:42:28 +08:00
{
2020-12-22 21:11:22 +01:00
/** @var Song|string */
2015-12-13 12:42:28 +08:00
protected $song;
2020-12-22 21:11:22 +01:00
/** @var string */
2015-12-13 12:42:28 +08:00
protected $contentType;
2018-08-22 19:59:14 +02:00
public function __construct()
{
// Turn off error reporting to make sure our stream isn't interfered.
@error_reporting(0);
}
2018-08-24 17:27:19 +02:00
public function setSong(Song $song): void
2015-12-13 12:42:28 +08:00
{
2015-12-27 20:29:03 +07:00
$this->song = $song;
2015-12-13 12:42:28 +08:00
2016-06-13 17:04:42 +08:00
abort_unless($this->song->s3_params || file_exists($this->song->path), 404);
2015-12-13 12:42:28 +08:00
// Hard code the content type instead of relying on PHP's fileinfo()
// or even Symfony's MIMETypeGuesser, since they appear to be wrong sometimes.
2018-08-22 19:59:14 +02:00
if (!$this->song->s3_params) {
2020-12-22 21:11:22 +01:00
$this->contentType = 'audio/' . pathinfo($this->song->path, PATHINFO_EXTENSION);
2018-08-22 19:59:14 +02:00
}
2015-12-13 12:42:28 +08:00
}
}