Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playing a WAV file on iOS Safari

I'm struggling to get a WAV file to play on a HTML page as either an HTML5 audio tag or via a regular downloadable link in mobile Safari (iPad/iPhone):

<audio controls src="audio-pcm_s16le-8k.wav"/></audio>
<a href="audio-pcm_s16le-8k.wav">audio</a>

The HTML5 audio object just shows Cannot play audio file in it, and when I click to download the anchor referenced one I get a black page with a "can't play this circle" in the middle. I've tried various frequencies (8000, 11025, 16000, 32000, 44100), various encodings (mu-law, Linear Signed 16-bit LE and BE), various containers (.wav, .caf, .aiff), and various audio conversion programs (Audacity, ffmpeg, and Apple's own afconvert)... I can't get audio to play (unless I make it MP3 -- and no, I can't just use MP3 or AAC, I need a "raw" format for reasons too long to get in to here).

I looked at the supported formats for iOS and it appears to support WAV... anyone got any experience with this issue? I'm on latest iOS 6.0.1

EDIT: The selected answerer got me to the issue, but the reason is in the comments of the answer. Bottom line is it requires HTML range headers for playing the files.

like image 223
mark Avatar asked Nov 07 '12 17:11

mark


People also ask

Can safari play WAV files?

Wav audio format is Fully Supported on Safari 15, which means that any user who'd be accessing your page through Safari 15 can see it perfectly.

How do I play WAV files on iOS?

Download WAV files player. If you don't want to convert WAV files or don't have a computer nearby, you can play WAV files on your iPhone by using WAV Media Player apps like VLC, MX Player, and PlayerXtreme Media Player, and others. Once you install the media Player, WAV files can be played normally with these players.

Can iOS open WAV files?

iPhone can't play WAV files natively. Well, what should you do if you want to play WAV audio recording on the iPhone? The best solution is to convert WAV to iPhone compatible formats. If you want to convert WAV to MP3 for playback on iPhone, you'll need a professional audio converter program to finish the task.

Does Apple support WAV format?

It is cross platform, too, so you'll get the same features and interface across all operating systems, whether you use Linux, Windows, or MacOS (also supports Android and iOS).


2 Answers

Well, you've certainly gotten me on the right track at least... it's apparently not the file at all... it's the web server. Same exact content from stockley works, but on my web server it doesn't. I'll have to look over the HTTP response in detail I suppose. My web server is returning Content-Type: audio/x-wav so it's not that...

Checking the headers for the test site I set up, you want to be returning Content-Type: text/html for the page containing the HTML data you need:

enter image description here

And Content-Type: audio/x-wav for the actual audio file (http://www.test.com/file.wav)

enter image description here

like image 105
WDUK Avatar answered Oct 22 '22 18:10

WDUK


Through a run of trial and error I found that you need a content-range header for it to work. Here's an example of my headers that allows a wav file to play in Safari for iOS:

Content-Range: bytes XX-XX/XX
Content-Type: audio/wav 
Content-Disposition: attachment; filename="whatever.WAV" 
Content-Length: XX    

Hope this helps!

like image 27
Oliver Mahoney Avatar answered Oct 22 '22 17:10

Oliver Mahoney