Comments (6)
Hmm it seems like the wrong place to initialize the code. Why are you not initializing the code at the end of the body?
from audio5js.
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.
from audio5js.
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.
from audio5js.
Errr... the library does make the following (justifiable) assumptions:
- It's considered good practice to wait for end of or DOM readiness to run your JS code.
- You make some sacrifices if you need Flash-based audio because of the nature of Flash in the browser.
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.
from audio5js.
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 ;-)
from audio5js.
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:
- Audio5js is an HTML5 audio compat. layer, rather than a DOM readiness compat. layer
- The developer most likely already uses a DOM library and has the facility to detect DOM readiness in a cross platform way.
- For the most part Audio5js doesn't manipulate the DOM
from audio5js.
Related Issues (20)
- Setting volume on ready event causes TypeError HOT 6
- Error when on https HOT 4
- one instance has issues loading multiple tracks HOT 4
- Playback speed support HOT 3
- Instance attribute 'position' is a formatted string. HOT 1
- milli seconds for progress HOT 4
- npm does not install latest release HOT 6
- Button to control sound in webpage HOT 3
- Angular implementation
- Catch HTTP response errors when loading audio? HOT 2
- Replay issue in IE8 HOT 1
- trigger 'canplaythrough' and 'stalled' HOT 1
- No Audio Android Chrome, But Full Audio Android Firefox?? HOT 13
- Uncaught (in promise) DOMException: play() can only be initiated by a user gesture. HOT 4
- fail to get audio duration directly HOT 6
- failed to pause playing immediately after this.play() HOT 3
- can laod Multiple songs at one time HOT 1
- any method to clear the event queue of specific event? HOT 4
- Uncaught (in promise) DOMException: play() failed because ... HOT 11
- Can't get info when loaded or play
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audio5js.