I am building an a/v html5 streaming web app. This question pretains to the audio portion of the project, but i\'m sure i will run into a similar situation when i get start
The HTML5 specification is still a draft under development so browsers that support it are essentially conforming to a yet-to-be-finalized spec. As such I wouldn't expect their HTML5 features to be fully functional...
I'm not sure what the current implementation landscape looks like for the progress
event, but when I was working on an HTML5 audio player several months ago I remember that I just couldn't get it to fire in Safari or Chrome. I ended up using a timer instead. Probably nothing you couldn't figure out, but here's a simplified version:
The Script:
$(document).ready(function(){
audio = $('body').find("audio").get(0);
});
function play() {
audio.play();
int = window.setInterval(updateProgress, 30);
}
function pause() {
audio.pause();
window.clearInterval(int);
}
function updateProgress() {
progress_seconds = Math.ceil(audio.currentTime);
progress_percent = Math.ceil(audio.currentTime / audio.duration * 100);
$('#progress_seconds').html('Seconds: ' + progress_seconds);
$('#progress_percent').html('Percent: ' + progress_percent);
};
The HTML:
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="so.js"></script>
<title></title>
</head>
<body>
<audio>
<source src="audio.mp3" type="audio/mp3">
</audio>
<a id="play" href="#" onclick="play();">Play</a>
<a id="pause" href="#" onclick="pause();">Pause</a>
<span id="progress_seconds">_</span>
<span id="progress_percent">_</span>
</body>
</html>
Progress events won't work in many use cases as of iOS 8.1. According to Apple's documentation:
Note: On the iPad, Safari does not begin downloading until the user clicks the poster or placeholder. Currently, downloads begun in this manner do not emit progress events.
I can corroborate that javascript triggered playback will not fire progress events. I have not tested using the HTML5 audio native controls <audio controls></audio
.
Ref: https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html