diff --git a/.gitattributes b/.gitattributes index 0a94073..2136101 100644 --- a/.gitattributes +++ b/.gitattributes @@ -42,3 +42,4 @@ *.aac binary *.wma binary *.au binary +*.rmi binary diff --git a/src/AudioFormat.php b/src/AudioFormat.php index a20e8f9..b87f807 100644 --- a/src/AudioFormat.php +++ b/src/AudioFormat.php @@ -20,4 +20,5 @@ final class AudioFormat public const AAC = 'aac'; public const WMA = 'wma'; public const AU = 'au'; + public const RMI = 'rmi'; } diff --git a/src/AudioMimeType.php b/src/AudioMimeType.php index 45c5d07..602895e 100644 --- a/src/AudioMimeType.php +++ b/src/AudioMimeType.php @@ -20,4 +20,5 @@ final class AudioMimeType public const AUDIO_AAC = 'audio/aac'; public const AUDIO_WMA = 'audio/x-ms-wma'; public const AUDIO_AU = 'audio/basic'; + public const AUDIO_RMI = 'audio/midi'; } diff --git a/src/Detector/RmiDetector.php b/src/Detector/RmiDetector.php new file mode 100644 index 0000000..8d64ee2 --- /dev/null +++ b/src/Detector/RmiDetector.php @@ -0,0 +1,33 @@ +fread(4); + $header = (string)$file->fread(25); + $hasIdentifiedHeader = strpos($header, 'RMIDdata') !== false || strpos($header, 'MThd') !== false; + + return $magicNumber === 'RIFF' && $hasIdentifiedHeader ? new AudioType( + AudioFormat::RMI, + AudioMimeType::AUDIO_RMI + ) : null; + } +} diff --git a/src/Provider/DefaultAudioProvider.php b/src/Provider/DefaultAudioProvider.php index 841de81..2beb0aa 100644 --- a/src/Provider/DefaultAudioProvider.php +++ b/src/Provider/DefaultAudioProvider.php @@ -15,6 +15,7 @@ use Selective\AudioType\Detector\AacDetector; use Selective\AudioType\Detector\WmaDetector; use Selective\AudioType\Detector\AuDetector; +use Selective\AudioType\Detector\RmiDetector; /** * All supported audio formats. @@ -40,6 +41,7 @@ public function getDetectors(): array new AacDetector(), new WmaDetector(), new AuDetector(), + new RmiDetector(), ]; } } diff --git a/tests/AudioTypeDetectorTest.php b/tests/AudioTypeDetectorTest.php index 3f8aacf..cd518d0 100644 --- a/tests/AudioTypeDetectorTest.php +++ b/tests/AudioTypeDetectorTest.php @@ -76,6 +76,7 @@ public function providerGetAudioTypeFromFile(): array 'AAC' => [__DIR__ . '/files/test.aac', AudioFormat::AAC, AudioMimeType::AUDIO_AAC], 'WMA' => [__DIR__ . '/files/test.wma', AudioFormat::WMA, AudioMimeType::AUDIO_WMA], 'AU' => [__DIR__ . '/files/test.au', AudioFormat::AU, AudioMimeType::AUDIO_AU], + 'RMI' => [__DIR__ . '/files/test.rmi', AudioFormat::RMI, AudioMimeType::AUDIO_RMI], ]; } diff --git a/tests/files/test.rmi b/tests/files/test.rmi new file mode 100644 index 0000000..b961c2f Binary files /dev/null and b/tests/files/test.rmi differ