Play/Stop Live Audio Streams

Play and stop live audio streams instead of pausing them by toggling the audio element's volume.

HTML

<audio id='myAudioStream'>
  <source src='http://ca7.rcast.net:8018/;'>
</audio>
<a id='playPause' href='javascript:;'>Play/Pause Audio Stream</a>

CSS

#myAudioStream {
  display: none;
}

JavaScript

/*
 * Play/Stop Live Audio Streams
 * "audioElement" should be a jQuery object
 */
function streamPlayStop(audioElement) {
  if (audioElement[0].paused) {
    audioElement[0].play();
  } else if (!audioElement[0].volume) {
    audioElement[0].volume = 1;
  } else {
    audioElement[0].volume = 0;
  }
}

$(document).ready(function() {
  $('#playPause').click(function() {
    streamPlayStop($('#myAudioStream'));
  });
});