Menu

#246 Basic interface for window.Audio

2.26
closed
1
2017-04-22
2017-04-04
No

Hi,

trying to render a page with Ember.js and getting blocked on the usage of window.Audio

var notificationSound = new window.Audio('/path/to.mp3');
notificationSound.play()

Window.Audio is not at all supported, and returns 'Undefined' which prevents to make the .play() call on it.
Locally, I can use a polyfill as workaround, by injecting it at the beginning of the javascript file, but ultimately some basic dummy support for the Audio object is needed. It's ofcourse not needed to play the sound, but at least to fake the support for the operation, otherwise the page rendering fails.

Here is the polyfill I use:

//AUDIO Pollyfil

window.Audio = function(path){
    return {
    'play':function(){
        return new Promise(function(resolve, reject) {
         resolve();
      }); 
    },
    'pause':function(){
        //no-op
    },
    'canPlayType':function(mimne){
        //As this just simulates playing audio. We might
      //as well claim we support everything.
      //Other options are: maybe or empty string
        return 'probably';
    }
  }
}

var k = new window.Audio('yo');
console.log(k.play());
console.log(k.pause());

Best,
Natasha

Discussion

  • Ahmed Ashour

    Ahmed Ashour - 2017-04-04
    • status: open --> accepted
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-04-05

    HTMLAudioElementTest.audio() was added as @NotYetImplemented

     
  • Ahmed Ashour

    Ahmed Ashour - 2017-04-22
    • status: accepted --> closed
    • assigned_to: Ahmed Ashour
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-04-22

    Thanks for reporting, fixed in SVN.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.