Comments (9)
Thanks for the advice anyway. I'm suspecting that your solution (instantiating another player) will be the one here, but let's wait for @eshaz's response too.
from icecast-metadata-js.
Hi @karolyi,
I think @eshaz can answer this question better, but I was in the same shoes.
I could solve it by making the player object static and call stop before I started another source. It is working perfectly.
The next code is used in React, but it may help:
`
let streamPlayer: IcecastMetadataPlayer | undefined = undefined;
const playAsync = async (url: string): Promise => {
streamPlayer = new IcecastMetadataPlayer(
url
);
await streamPlayer.play();
}
const stop = (): void => {
await streamPlayer?.stop();
await streamPlayer?.detachAudioElement();
}
`
Hope this helps.
from icecast-metadata-js.
The code is a bit garbled to me but if I understand it right, you basically instantiate a new player whenever you want to play another source? If that's the case, why do you need to detach the audio element?
from icecast-metadata-js.
It says that detachAudioElement
is only necessary if you've passed your own audio element for use with the player.
I'm assuming some former version of your code had it?
from icecast-metadata-js.
I just tried to copy the code and remove all the unnecessary parts, but with less success. I also use HTMLAudioElement and detachAudioElement was needed for other kinds of purposes.
Anyhow, if you only need to stop the audio, switch the URL and start, you may try to switch it by changing the underlying audio element source:
streamPlayer.audioElement.src = ""
Anyhow, it was not tested at my side, so I'm not 100% sure it is the right solution.
from icecast-metadata-js.
Anyhow, if you only need to stop the audio, switch the URL and start, you may try to switch it by changing the underlying audio element source:
streamPlayer.audioElement.src = ""
I was looking into that too, but the audio element has an internal blob source (possibly coming from the decoder part of the player) as a source, and with changing that to the URL you'd lose the metadata decoding ability.
from icecast-metadata-js.
Probably, that is another reason I was made my solution as it is, but I also play regular audio files by using my own audio element, not just streams.
So, maybe I could not give you better advice at this moment than recreate the IcecastMetadataPlayer object, but maybe the creator of this plugin could give better hints.
from icecast-metadata-js.
you basically instantiate a new player whenever you want to play another source?
Yes, to change the source you need to create a new instance with the new endpoint passed into the constructor. Once the instance is constructed, there's intentionally no way to change the source URL. There is internal state in the player that is set up when the first call to play()
happens that makes it impossible to change the source URL in the current design. Changing the audio element source won't work and might cause unexpected behavior / errors.
It says that
detachAudioElement
is only necessary if you've passed your own audio element for use with the player.
Yes, this is correct. This method is only needed when you want to reuse your audio element for something else after you're done with the IcecastMetadataPlayer
instance.
Here's a code example in the demo for this project that does this. After you've called stop()
on your instance, you can create a new instance with the new URL, call play()
, and let the old instance be garbage collected.
from icecast-metadata-js.
Thanks for your response reinforcing my thoughts! Closing this issue.
from icecast-metadata-js.
Related Issues (20)
- 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
- Audio stops playing after 5 seconds. HOT 4
- Unable to resume audio on iOS 17
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.