Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long buffering for specific radio stations #22

Open
thehijacker opened this issue Apr 20, 2021 · 1 comment
Open

Long buffering for specific radio stations #22

thehijacker opened this issue Apr 20, 2021 · 1 comment

Comments

@thehijacker
Copy link

Hello,

For last few hours I am trying to debug long buffering on specific radio stations like this two:

https://scdn.nrjaudio.fm/adwz1/de/33047/mp3_128.mp3
http://live.1chi.si/vrabcek

It can take up to 20 seconds to start. If I press pause and play again as soon as station is selected it will start playing it instantly.

Same works with catt.

I am struggling with modifying function onStationSelect(e) to add some kind of delay or check if stream is in fact playing. If it would not then I would issue only play on it as suggested in pychromecast forums.

Can someone that knows a bit better JS and HA functions, give me/us a little help to solve this?

Thank you and best regards,
Andrej

@thehijacker
Copy link
Author

Best I could do without blocking entire browser.

I try to call service media_play every 0,5 seconds for 5 seconds in total after I switch to station. Now streams that would normally take 20 seconds to start, start in 1 to 4 seconds max.

    onStationSelect(e) {
        this.hass.callService('media_player', 'play_media', {
            entity_id: this._selectedSpeaker,
            media_content_id: e.currentTarget.stationUrl,
            media_content_type: 'music',
            extra: {
                metadata: {
                stream_type: "LIVE",
                metadataType: 3,
                title: e.currentTarget.stationName,
                artist: "Live Radio",
                images: [
                    { url: e.currentTarget.stationLogo }
                    ]
                }
            }
        });
        var that = this;
        var i = 0;
        for (i = 500; i <= 5000; i=i+500)
        {
            setTimeout(function() {
                that.hass.callService('media_player', 'media_play', {
                    entity_id: that._selectedSpeaker
                }); }, i);
        }
    }

I am open for improvement of this code. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant