Skip to content

Commit

Permalink
Merge pull request #47 from open-source-contributions/issue_#22
Browse files Browse the repository at this point in the history
Resolves issue #22
  • Loading branch information
odan authored Jul 21, 2020
2 parents 1f47788 + 8262876 commit 8d2d60b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
*.aac binary
*.wma binary
*.au binary
*.rmi binary
1 change: 1 addition & 0 deletions src/AudioFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ final class AudioFormat
public const AAC = 'aac';
public const WMA = 'wma';
public const AU = 'au';
public const RMI = 'rmi';
}
1 change: 1 addition & 0 deletions src/AudioMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
33 changes: 33 additions & 0 deletions src/Detector/RmiDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Selective\AudioType\Detector;

use Selective\AudioType\AudioFormat;
use Selective\AudioType\AudioMimeType;
use Selective\AudioType\AudioType;
use SplFileObject;

/**
* Detector.
*/
final class RmiDetector implements AudioDetectorInterface
{
/**
* Detect RMI, RIFF-MIDI audio format.
*
* @param SplFileObject $file The audio file
*
* @return AudioType|null The audio type
*/
public function detect(SplFileObject $file): ?AudioType
{
$magicNumber = (string)$file->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;
}
}
2 changes: 2 additions & 0 deletions src/Provider/DefaultAudioProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,6 +41,7 @@ public function getDetectors(): array
new AacDetector(),
new WmaDetector(),
new AuDetector(),
new RmiDetector(),
];
}
}
1 change: 1 addition & 0 deletions tests/AudioTypeDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand Down
Binary file added tests/files/test.rmi
Binary file not shown.

0 comments on commit 8d2d60b

Please sign in to comment.