selva
selva

Reputation: 314

How to play m4a audio file in html audio player in MAC SAFARI browser

I have implemented a web application which uses html audio player. We will be having two type of audio files

mp3 m4a

both files are playing fine in windows chrome, edge and firefox.

Regarding m4a file in safari browser it was throwing Error instead of playing.We tried with below cases

Case 1: Added Mime extension and audio type to "audio/mp4".

Case 2: Added audio type to "audio/x-m4a".

Case 3: Does not provided audio type.

<audio controls><source src="Audio.m4a" type="audio/mp4"></audio>

Upvotes: 1

Views: 4137

Answers (2)

user3092381
user3092381

Reputation: 31

This would vary depending on which OS version and browser versions you have, but the following works on MacOS Catalina in both Safari and Chrome.

<audio controls>
    <source src="test.m4a" type="audio/x-m4a">
    <source src="test.mp3" type="audio/mp3">
    Your browser does not support the audio tag.
</audio>

Note the "audio/x-m4a" type for .m4a files.

You can check for audio player type compatibility by grabbing the HTMLAudioElement and calling:

console.log("Can play m4a:" + audioElement.canPlayType('audio/x-m4a'));

Upvotes: 3

selva
selva

Reputation: 314

Am closing this task with answer as M4A cannot be played in MAC Safari browser in html audio player tag after trying out all possible solutions across different sites

Upvotes: 1

Related Questions