Closed bjoerge closed 11 years ago
Hmm it seems like the wrong place to initialize the code. Why are you not initializing the code at the end of the body?
I don't see any good reason for this library to make assumptions about the DOM state. Moreover, this is not a problem in browsers supporting HTML5 audio. As Audio5js is a compatibility layer and the flash fallback should do its best to avoid introducing bugs in environments is providing compatibility for.
The fix is simple, just wrap the document.body.appendChild(d)
in a domready event handler.
Btw, the code above were just an illustrating example, I'm creating an instance of Audio5js in a script loaded via <script src="the-script.js" async defer></script>
. This tag is located in <head>
and that makes perfectly sense to me.
Errr... the library does make the following (justifiable) assumptions:
I don't think the library should concern itself with DOM readiness (which is in itself incompatible between browsers). If you implement the library, you should be mindful of the DOM manipulation in FF, which requires DOM readiness and implement the code accordingly.
I'm happy to add a note in README at reminds people of this, but I see no reason to change the code to check for DOM readiness.
It's considered good practice to wait for end of or DOM readiness to run your JS code.
That is true for the parts of the JS code that interacts with the DOM. There are perfectly good reasons to run javascript that doesn't care about the DOM before the DOM ready (side point: I don't really feel it is in the Audio5js mandate to enforce good practice on its users, it is a compatibility layer after all).
You make some sacrifices if you need Flash-based audio because of the nature of Flash in the browser.
That is true for the unavoidable sacrifices (like flash installed). However, my point is that "wait for dom ready" is a hidden requirement that isn't really necessary and are causing surprising errors. Sure, a note in the README will help those who fine read it, but is in my opinion not a proper fix.
Anyways, I've fixed this by including the domready lib in my fork. I sense that a pull request is not too welcome here, so I'll just keep it to myself for now ;-)
Hmm, i'm afraid we'll have to agree to disagree. My sentiment is that Audio5js should solve HMTL5 audio compatibility issues and that's all.
Yes, DOM readiness is a hidden requirement, but it's also a hidden requirement for the Facebook JS SDK which doesn't immediately strikes one as DOM-reliant. I don't see why you can't simply use your own DOM readiness mechanism inside the
section of your code, since you're aware of that requirement.In other words, why should Audio5js be responsible for DOM readiness detection, when:
The element containing the flash embed code is tried appended to
document.body
at a time whendocument.body
may not be set (depending on when audiojs is initialized).I.e. the following will break flash fallback:
Offending line is this: zohararad/audio5js/src/audio5.js#L209