Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html5 (audio) on Safari & iOS

I am working on a web application and I have one compatibility problem with Apple devices & Safari on PCs.

Html5 audio tag:

<audio controls>
<source src="/audio/en/file.mp3" type="audio/mpeg">
<source src="/audio/en/file.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
  • I just want to play an audio file with basic controls.
  • The previous code works perfectly on Chrome, Opera, Firefox (Windows & Android devices).
  • But controlers do no appear with Safari (tested with the latest version on PC, iPad & iPad mini).
  • Audio player have a grey background with only "play/pause" function.
  • Here is a screenshot that describes my problem :

Image

Thanks.

like image 550
ccarrez Avatar asked Jul 22 '14 07:07

ccarrez


People also ask

Does Apple Safari support HTML5?

Safari does not support HTML5 Save functionality. Help... This functionality works fine in Chrome, FireFox, Opera and even in IE and Edge.

Can I play audio in HTML5?

Since the release of HTML5, audios can be added to webpages using the “audio” tag. Previously, audios could be only played on web pages using web plugins like Flash. The “audio” tag is an inline element that is used to embed sound files into a web page.


1 Answers

I had exactly the same problem.

My solution: I added the full URL for the audiofile source. Don't know why but it makes a difference. Here's my full code. The CSS modifications are only to hide the download button. But when I take it out I don't see the timeline. Very strange but exactly this code works for me.

<!DOCTYPE html>
<html>
<head>
    <title>html5 audio player on iPhone</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
<style>
audio::-internal-media-controls-download-button {
    display:none;
}
audio::-webkit-media-controls-enclosure {
    overflow:hidden;
}
audio::-webkit-media-controls-panel {
    width: calc(100% + 33px);
}  
</style>
</head>
<body>
<audio controls preload="auto" style="width:100%;">
    <source src="https://example.com/audio/audiofile.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio><br />
</body>
</html>
like image 117
user7103188 Avatar answered Sep 18 '22 05:09

user7103188