Skip to content

Commit

Permalink
Fixes #5390 Incorrect mime-type when using toAudio() with .wav files.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Jan 14, 2025
1 parent b51833b commit e8f5e80
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
22 changes: 21 additions & 1 deletion e107_handlers/e_parse_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4931,7 +4931,27 @@ public function toAudio($file, $parm = array())

$file = $this->replaceConstants($file, 'abs');

$mime = varset($parm['mime'], 'audio/mpeg');
$ext = pathinfo($file, PATHINFO_EXTENSION);

switch (strtolower($ext))
{

case 'wav':
$mime = 'audio/wav';
break;
case 'ogg':
$mime = 'audio/ogg';
break;
case 'mp3':
default:
$mime = 'audio/mpeg';
break;
}

if(!empty($parm['mime']))
{
$mime = $parm['mime'];
}

$autoplay = !empty($parm['autoplay']) ? 'autoplay ' : '';
$controls = !empty($parm['controls']) ? 'controls' : '';
Expand Down
19 changes: 18 additions & 1 deletion e107_tests/tests/unit/e_parseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2659,7 +2659,24 @@ public function testtoAudio()
</audio>';

$result = $this->tp->toAudio('{e_MEDIA}myfile.mp3');
$this->assertEquals($expected, $result);
self::assertEquals($expected, $result);

$expected = '<audio controls style="max-width:100%" >
<source src="/e107_media/000000test/myfile.wav" type="audio/wav">
Your browser does not support the audio tag.
</audio>';

$result = $this->tp->toAudio('{e_MEDIA}myfile.wav');
self::assertEquals($expected, $result);

// Override mime.
$expected = '<audio controls style="max-width:100%" >
<source src="/e107_media/000000test/myfile.php" type="audio/wav">
Your browser does not support the audio tag.
</audio>';

$result = $this->tp->toAudio('{e_MEDIA}myfile.php', ['mime' => 'audio/wav']);
self::assertEquals($expected, $result);

}

Expand Down

0 comments on commit e8f5e80

Please sign in to comment.