koel/app/Services/Streamers/Streamer.php

31 lines
843 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
2017-04-20 11:20:32 +00:00
namespace App\Services\Streamers;
2015-12-13 04:42:28 +00:00
use App\Models\Song;
use App\Values\SongStorageMetadata\LocalMetadata;
2015-12-13 04:42:28 +00:00
class Streamer implements StreamerInterface
2015-12-13 04:42:28 +00:00
{
2021-06-05 10:47:56 +00:00
protected ?Song $song = null;
2015-12-13 04:42:28 +00:00
2021-06-05 10:47:56 +00:00
protected ?string $contentType = null;
2015-12-13 04:42:28 +00:00
2018-08-22 17:59:14 +00:00
public function __construct()
{
// Turn off error reporting to make sure our stream isn't interfered.
@error_reporting(0);
}
2018-08-24 15:27:19 +00:00
public function setSong(Song $song): void
2015-12-13 04:42:28 +00:00
{
2015-12-27 13:29:03 +00:00
$this->song = $song;
2015-12-13 04:42:28 +00: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.
if ($this->song->storage_metadata instanceof LocalMetadata) {
$this->contentType = 'audio/' . pathinfo($this->song->storage_metadata->getPath(), PATHINFO_EXTENSION);
2018-08-22 17:59:14 +00:00
}
2015-12-13 04:42:28 +00:00
}
}