N
N
Nikita Kit2017-02-07 12:18:15
JavaScript
Nikita Kit, 2017-02-07 12:18:15

Why is the broadcast stream interrupted in audio?

Hello everyone dear community.
I am not engaged in the most common task - they asked me to tie the streams of radio stations to the radio. I haven't worked with the audio tag before and it disappoints me. It seems to me that there is something enabled by default in it that creates a bug.
In general, I dug up links to the broadcasts of various stations, wrote a script to turn on and off the player for these streams. as a result, a simple script came out

var player = document.getElementById('audio');
    var isPlaying = false;
    function togglePlay() {
        if (isPlaying) {
            player.pause();
            player.currentTime = 0;//added
            player.src = '';//added
            isPlaying = false;
            console.log(isPlaying);
        } else {
            player.src = stations.maximum;//added
            player.load();//added
            player.play();
            isPlaying = true;
            console.log(isPlaying);
        }
    }
    switchBtn.click(function(){
        togglePlay();
    });

What was added was added in an attempt to eliminate the bug, and the symptom is strange - after the first turn on everything works like clockwork, after the first pause and re-turn on (in the interval of 10-15 seconds) the stream plays for 5 seconds (and repeats next to the fragment, after which he paused) and is cut down. It turns on again if you just wait about a minute and turn it on again.
10 times ran through the debugger - the script works correctly. I tried toggling src - it didn't work. I tried to add load before playing - it did not work. I tried adding preload='none' to the tag - also to no avail. I'm running out of ideas - what's wrong? Maybe the idea of ​​playing streams through the url simply does not have the right to life? If so, how is it possible to implement the idea?
Thank you all, dear forum users.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Kit, 2017-02-07
@ShadowOfCasper

Everything worked in firefox, the problem was only in chrome. While browsing through stackoverflow, I came across a solution. buzz.jaysalvat.com I
actually wrote down the script on the docks and everything plows correctly and without jambs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question