Skip to content

Commit

Permalink
Merge pull request #45 from open-source-contributions/issue_#21
Browse files Browse the repository at this point in the history
Resolves issue #21
  • Loading branch information
odan authored Jul 21, 2020
2 parents 3099d2b + e2e736c commit 3ec345f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
*.caf binary
*.aac binary
*.wma binary
*.au binary
1 change: 1 addition & 0 deletions src/AudioFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ final class AudioFormat
public const CAF = 'caf';
public const AAC = 'aac';
public const WMA = 'wma';
public const AU = 'au';
}
1 change: 1 addition & 0 deletions src/AudioMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ final class AudioMimeType
public const AUDIO_CAF = 'audio/x-caf';
public const AUDIO_AAC = 'audio/aac';
public const AUDIO_WMA = 'audio/x-ms-wma';
public const AUDIO_AU = 'audio/basic';
}
31 changes: 31 additions & 0 deletions src/Detector/AuDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Selective\AudioType\Detector;

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

/**
* Detector.
*/
final class AuDetector implements AudioDetectorInterface
{
/**
* Detect AU audio file
*
* @param SplFileObject $file The audio file
*
* @return AudioType|null The audio type
*/
public function detect(SplFileObject $file): ?AudioType
{
$bytes = (string)$file->fread(4);

return $bytes === '.snd' ? new AudioType(
AudioFormat::AU,
AudioMimeType::AUDIO_AU
) : null;
}
}
2 changes: 2 additions & 0 deletions src/Provider/DefaultAudioProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Selective\AudioType\Detector\CafDetector;
use Selective\AudioType\Detector\AacDetector;
use Selective\AudioType\Detector\WmaDetector;
use Selective\AudioType\Detector\AuDetector;

/**
* All supported audio formats.
Expand All @@ -38,6 +39,7 @@ public function getDetectors(): array
new CafDetector(),
new AacDetector(),
new WmaDetector(),
new AuDetector(),
];
}
}
1 change: 1 addition & 0 deletions tests/AudioTypeDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function providerGetAudioTypeFromFile(): array
'CAF' => [__DIR__ . '/files/test.caf', AudioFormat::CAF, AudioMimeType::AUDIO_CAF],
'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],
];
}

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

0 comments on commit 3ec345f

Please sign in to comment.