adapter = $adapter ?? $this->resolveAdapter(); } private function resolveAdapter(): StreamerAdapter { throw_unless(SongStorageTypes::supported($this->song->storage), KoelPlusRequiredException::class); if ($this->shouldTranscode()) { return app(TranscodingStreamerAdapter::class); } return match ($this->song->storage) { SongStorageTypes::LOCAL, '' => app(LocalStreamerAdapter::class), SongStorageTypes::S3, SongStorageTypes::S3_LAMBDA => app(S3CompatibleStreamerAdapter::class), SongStorageTypes::DROPBOX => app(DropboxStreamerAdapter::class), default => throw UnsupportedSongStorageTypeException::create($this->song->storage), }; } public function stream(): mixed { return $this->adapter->stream($this->song, $this->config); } private function shouldTranscode(): bool { // We only transcode local files. "Remote" transcoding (e.g., from Dropbox) is not supported. if ($this->song->storage !== SongStorageTypes::LOCAL) { return false; } if (Arr::get($this->config, 'transcode', false)) { return true; } return $this->song->storage === SongStorageTypes::LOCAL && Str::endsWith(File::mimeType($this->song->storage_metadata->getPath()), 'flac') && config('koel.streaming.transcode_flac') && is_executable(config('koel.streaming.ffmpeg_path')); } public function getAdapter(): StreamerAdapter { return $this->adapter; } }