koel/app/Http/Streamers/Streamer.php

38 lines
791 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Streamers;
use App\Models\Song;
2016-02-02 08:01:47 +00:00
class Streamer
2015-12-13 04:42:28 +00:00
{
/**
* @var Song|string
*/
protected $song;
/**
* @var string
*/
protected $contentType;
/**
* BaseStreamer constructor.
*
2015-12-27 13:29:03 +00:00
* @param $song Song
2015-12-13 04:42:28 +00:00
*/
2015-12-27 13:29:03 +00:00
public function __construct(Song $song)
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
abort_unless(file_exists($this->song->path), 404);
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.
$this->contentType = 'audio/'.pathinfo($this->song->path, PATHINFO_EXTENSION);
// Turn off error reporting to make sure our stream isn't interfered.
@error_reporting(0);
}
}