title: Cordova media plugin - stop streaming not working - release() freezes the device
body: <p>I am using <code>cordova 6.4.0</code> with <code>cordova-plugin-media</code> for streaming radio-stations in an Android Application. Unfortunately there is a case, where the application is not responding properly anymore.</p>
  
  <p>Let's say the user wants to stream a radiostation, but while the stream is loading, he wants to abort it (for example because the stream is down, or taking very long to load).</p>
  
  <p>In this case I am not able to cancel the process!</p>
  
  <pre><code>media = new Media("http://direct.franceinfo.fr/live/franceinfo-midfi.mp3?ID=f9fbk29m84", mediaPlayerSuccess, mediaPlayerFail, mediaPlayerStatus);
  media.play();
  </code></pre>
  
  <p>Now I want to cancel the process of buffering the stream, but I'm not able to. The functions:</p>
  
  <pre><code>media.pause();
  media.stop();
  </code></pre>
  
  <p>are throwing error messages in the ADB-log and are calling the mediaPlayer-onError callback.</p>
  
  <pre><code>D/AudioPlayer( 3362): AudioPlayer Error: pausePlaying() called during invalid state: 1
  ...
  D/AudioPlayer( 3362): AudioPlayer Error: stopPlaying() called during invalid state: 1
  </code></pre>
  
  <p>The <code>media.release()</code> command stops the loading of the stream! However just releasing the stream without stopping it, causes other, rather big problems:</p>
  
  <p>Most of the times the system reacts just very slow and hangs a few seconds, if you call <code>media.release()</code> on a media-object. But if you do this often, the system <strong>completly freezes</strong>. Meaning it does not accetp remote-control commands anymore.
  The Adb-log is still working, but does not show any errors in this case. Only the POWER-Button is still working (it locks and unlocks the screen). The only way to recover from this screwed-up state, is to reboot the device.</p>
  
  <p><strong>How am I supposed to cancel a Media-stream if it is not playing, yet? Is this a bug in the plugin?</strong></p>
  
  <p>Attached is the code-snippet, that I use to handle the media-streaming-logic. Like described above... it basically works, but it slows down or even freezes device, if you call it multiple times.</p>
  
  <pre><code>function radioControl(action, media_src){
    //media_src is a webradio-streamurl.
  
    if(action == 'play') {
  
      // Initial Play
      if(media === null){
        mediaCreateObject(media_src);
      }
  
      // If we get PLAY but on antoher station
      else if(media.src != media_src){
        mediaReleaseRessources();
        mediaCreateObject(media_src);
      }
  
      //interrupt_timer = false;
      if(media === null){
        mediaCreateObject(media_src);
      }
      media.play();
    }
    else if (action === 'pause') {
      //If we get "pause", but it didn't even start yet
      if(media._duration == -1){
        mediaReleaseRessources();
      }
      else{
        media.pause();
      }
    }
  }
  
  function mediaCreateObject(media_src){
    media = new Media(media_src, mediaPlayerSuccess, mediaPlayerFail, mediaPlayerStatus);
  }
  
  function mediaReleaseRessources(){
    media.release();
  }
  </code></pre>