Comments (13)
I think this is a good idea. I'm thinking it could be implemented slightly differently though.
The bulk of the code size is consumed by the wasm-audio-decoders
and the synaudio
libraries. The metadata functionality is actually quite small in comparison, probably less than 10kB.
I think it would be good to have these features able to be selectively enabled / disabled so that when they are disabled, the extra code isn't bundled when used with a bundler such as webpack or rollup.
One main example would be that if you only ever use Opus for your stream, you won't need the MP3 or FLAC decoders, which would save about 150kB. Or if you don't want iOS support / WebAudio, you could remove the decoders altogether.
This kind of change would require some significant refactoring of the existing code, but I'll take a look at this.
from icecast-metadata-js.
@eshaz Is there anyway we can have a quick conversation about that?
from icecast-metadata-js.
We can, but I would prefer to use this issue thread so that others can reference this in the future. Will that work?
from icecast-metadata-js.
I think it would be good to have these features able to be selectively enabled / disabled so that when they are disabled, the extra code isn't bundled when used with a bundler such as webpack or rollup.
One main example would be that if you only ever use Opus for your stream, you won't need the MP3 or FLAC decoders, which would save about 150kB. Or if you don't want iOS support / WebAudio, you could remove the decoders altogether.
You are absolutely right, that is even better :)
If we're going this route, imho the best way to achieve that is not to pre-configure which modules/decoders/mechanisms you're going to use, but rather have them dyanmically imported on a "need" basis, for instance, if an Opus stream is initiated and we're on a platform that doesn't support native playback, await import() the desired module to handle this situation, same goes for the metadata mechanisms and cross-play feature.
from icecast-metadata-js.
await import() the desired module
That's a good idea, and probably the way to go.
It would be preferable to have the dependencies pulled in as needed, but I'm wondering if bundlers would be able to evaluate the condition whether or not to execute the import
if it happens during runtime. There might have to be a hard coded parameter set on the library that bundlers could use to evaluate the conditional import
statements and strip out those unused dependencies.
It seems reasonable for those who want to save a couple hundred kilobytes to explicitly enable / disable features if it can't be done at runtime. Just for reference, the minified bundle with all features including MP3, Flac and Opus audio decoders is 273KiB.
from icecast-metadata-js.
@Yahav, it turns out the await import()
solution works great with webpack.
If you want to take a look, I have #164 that splits the icecast-metadata-player
into separate files that are downloaded as needed by the library. This should allow for a bit less data to be loaded on the initial page load.
from icecast-metadata-js.
Amazing! I'll have a look into this later this week.
This dynamic import loads the different kind of encoders, how about the rest of the optional mechanisms, like the metadata fetching, are those something that you might be able to dynamically import as well?
from icecast-metadata-js.
The metadata fetching isn't all that much code, and it's tightly integrated with everything else so I'm going to leave that built in for now.
The main reason to do this is to reduce the initial load time and total size, which is enhanced the most by deferring the decoders.
from icecast-metadata-js.
Not sure if that's intended. but when setting the playback method to html5, the mediasource.js file is loaded anyway.
If you select mediasource as the playback method, it loads it twice, once when the page loads and again when you play the audio.
from icecast-metadata-js.
@eshaz
As an addition to the above reply.
I found out that we can save further size by dynamically loading the EmscriptenWasm.js as well, it takes a rather large size of each encoder..
from icecast-metadata-js.
It should be good as is. That file is needed for the WASM audio decoders to function, so it all needs to load if one of the decoders is also needed.
from icecast-metadata-js.
@eshaz ok.
What about that one though:
#163 (comment)
from icecast-metadata-js.
It preloads since most browsers use mediasource by default (everything except iOS), and then loads it again from cache in the import
. The preload made starting playback a bit more responsive at the cost of just a few extra KB downloaded for iOS users.
from icecast-metadata-js.
Related Issues (20)
- DOMException: The play() request was interrupted because the media was removed from the document HOT 3
- Depricated code HOT 1
- Station name from metadata? HOT 2
- Deferred module loading? HOT 1
- 'IcecastReadableStream' is not exported from 'icecast-metadata-js' (imported as 'IcecastReadableStream') HOT 8
- webaudio analyser ? HOT 3
- Full screen visualizer in demo
- multiple instances of metadata HOT 4
- icecast-metadata-stats NodeJS support HOT 6
- Authenticated streams not working? HOT 4
- CORS or header problem from icecast2 HOT 3
- iOS does not recognize playback correctly
- AbortError with streams from Icecast 2.4.0-kh22 HOT 10
- Uncaught ReferenceError: player is not defined HOT 8
- Play and replay issue on iOS HOT 9
- icecast-metadata-player retry / reconnect logic not working in iOS 17 HOT 1
- icecast-metadata-player - navigator.mediaSession.metadata not working in iOS HOT 3
- Pass custom parameter into icecast-metadata-player-1.17.1.main.min.js HOT 5
- Writing metadata to a file HOT 2
- ReferenceError: Worker is not defined HOT 5
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 icecast-metadata-js.