I am creating an a / v html5 streaming web application. This question is about the audio part of the project, but I’m sure that I’ll face a similar situation when I start working on the video part. My target device is the Safari browser for iPad (hence why I should do this html5). Playback works fine, but I have a loading bar that should reflect how much of the track has been downloaded. Following the w3 spec, I tried to implement this as follows using jQuery:
var that = this; that.player = $('audio')[0]; $('that.player').bind('progress',function(){ var buffer = that.player.buffered.end(0) that.updateLoadBuffer(buffer); });
This did not work. 'that.player.buffered' returns a TimeRanges object, and TimeRanges has an end (index) method that returns the playback position of the end of the buffer in seconds for the TimeRange specified by the index. TimeRanges also has a .length property that tells you how many TimeRanges an object encapsulates. When I tried to write this property, I found that TimeRanges.length = 0, which means that TimeRanges is not being passed back. Also, when I ran the entries in a related function, I found that the progress event was never fired. I have separate functions for the events "loadedmetata" and "timeupdate" that follow a similar format and those that fire as expected. I tried other methods to capture events to no avail:
that.player.onprogress = function(e){ console.log('progressEvent heard'); }; that.player.addEventListener('progress',progressHandler, false) function progressHandler(e){ console.log('progressEvent heard'); };
None of them triggered my console message. The declaration of my audio tag is as follows:
<audio style="width:0;height:0;"></audio>
What am I doing wrong here?
UPDATE: I use wowzamediaserver to handle http streaming. I do not know if this has anything to do with it.
GIVE ANOTHER UPDATE: I understand that I don't have a source in the audio tag because I am setting it dynamically using jquery, as shown below:
$('audio').attr('src','http://my.wowza.server:1935/myStreamingApp/_definst_/mp3:path/to/my/track/audio.mp3/playlist.m3u8');
again, I have no problems with reproduction, so this should not have anything to do with my problem, but I just want to give you guys as clear a picture as possible.
jquery html5 events ipad audio-streaming
aamiri
source share