Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My workaround in an app that allows choosing of system sounds that may or may not have ANDROID_LOOP=true set involves checking the file and making a note as follows:
- window.resolveLocalFileSystemURL($('#soundfile').val(), function(entry){
- console.log('got file entry=',entry);
- entry.file(function(file){
- var reader = new FileReader();
- reader.onload = function(e) {
- this.result = this.result.substr(0,1024);
- if(this.result.toLowerCase().indexOf("android_loop=true")>0){
- console.log("ANDROID_LOOP=true detected!");
- settings.alarm_looper=true;
- } else if(settings.hasOwnProperty('alarm_looper')) delete settings.alarm_looper;
- // async, so..
- play_sound($('#soundfile').val());
- localStorage.setItem('settings',JSON.stringify(settings));
- }
- reader.readAsText(file);
- });
- }, function(e){
- console.log('failed to get file e=',e);
- if(settings.hasOwnProperty('alarm_looper')) delete settings.alarm_looper;
- });
- Then I use a setInterval that detects duration to play the sound:
- sound_start=new Date().getTime();
- media1.play({ numberOfLoops: 1 });
- // hack for bug where files with ANDROID_LOOP=true always loop
- if(settings.alarm_looper){
- sound_end=null;
- if(!handle.hasOwnProperty('media')) handle.media=setInterval(function(){
- // wait until media gives us the duration..
- if(media1._duration==-1){
- console.log('media1._duration=-1, interval return');
- return;
- } else if(sound_end===null) sound_end=Math.round(sound_start+(media1._duration*1000)-40);
- var now=new Date().getTime();
- if(now>=sound_end){
- console.log('now>=sound_end '+now+'>='+sound_end+' killing media');
- if(media1!=null) media1.release();
- if(handle.hasOwnProperty('media')){
- clearInterval(handle.media);
- delete handle.media;
- }
- sound_end=null;
- }
- }, 50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement