Mediaelementjs playing the cache instead of the current song

Asked

Viewed 31 times

0

I have the following code:

  $(document).ready(function(){

    var stream = 'http://somdomato.com:8000/stream.mp3';
    var nocache = '';

    $('#tocando').click(function(e) {
        e.preventDefault();
    });

    $('#player').mediaelementplayer({
      //   pluginPath: 'https://cdnjs.com/libraries/mediaelement/',
      //   shimScriptAccess: 'always',
      startVolume: 0.4,
      alwaysShowControls: true,
      features: ['playpause','volume'],
      audioWidth: 145,
      iPadUseNativeControls: true,
      iPhoneUseNativeControls: true,
      //AndroidUseNativeControls: true,
      success: function(player, node) {
        player.addEventListener('pause', function () {
        player.setSrc('');
      }, false);
      player.addEventListener('stalled', function () {
        var checkNetworkStateTimer = setInterval(function () {
          if (!paused) {
            if (node.networkState == 1 || node.networkState == 3) {
                                 var nocache = Math.floor((Math.random() * 1000000) + 1);
                                 player.setSrc(stream+'?nocache='+nocache);
                                 player.load();
                                 player.play();
                                 console.log('re-connecting after stalling due to networkState: '+node.networkState); //2 indicates NETWORK_LOADING state
                             }
                         }
                     }, 3000);

                 }, false);
         player.addEventListener('error', function () {
             var checkNetworkStateTimer = setInterval(function () {
                 if (!paused) {
                     if (node.networkState == 1 || node.networkState == 3) {
                         var nocache = Math.floor((Math.random() * 1000000) + 1);
                         player.setSrc(stream+'?nocache='+nocache);
                         player.load();
                         player.play();
                         console.log('re-connecting after error due to networkState: '+node.networkState); //2 indicates NETWORK_LOADING state
                     }
                 }
             }, 3000);
           }, false);




             },
             error: function () {
                 console.log('error log');
             }


    });


  });

But most of the time when pressing pause and then play the player plays a cached version instead of the current song in Streaming (Shoutcast + sc_trans).

I tried to follow that: https://github.com/mediaelement/mediaelement/issues/1321#issuecomment-84600421

But it did not work, the player sometimes plays and others it returns pro pause, or plays and does not pause...

Complete code: http://ix.io/zYM

  • Strange, the problem seems not to be in the code but in the url: http://somdomato.com:8000/stream.mp3 , even accessing it, the music continues as if it were in a cache, you have no other url to test?

  • But the point, not even the cache itself, is that the play/pause button doesn’t work properly, http://somdomato.com:8000 that’s the stream link. I have one version in production and one here on my PC to my PC that is with this problem...

  • Another very important thing that I tried and could not, is in this same code above, in case the stream falls and the player starts playing again alone...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.