examples/radio/radio.js
function(stations) {
  var self = this;

  self.stations = stations;
  self.index = 0;
  
  // Setup the display for each station.
  for (var i=0; i<self.stations.length; i++) {
    window['title' + i].innerHTML = '<b>' + self.stations[i].freq + '</b> ' + self.stations[i].title;
    window['station' + i].addEventListener('click', function(index) {
      var isNotPlaying = (self.stations[index].howl && !self.stations[index].howl.playing());
      
      // Stop other sounds or the current one.
      radio.stop();

      // If the station isn't already playing or it doesn't exist, play it.
      if (isNotPlaying || !self.stations[index].howl) {
        radio.play(index);
      }
    }.bind(self, i));
  }
}
function(stations) {
  var self = this;

  self.stations = stations;
  self.index = 0;
  
  // Setup the display for each station.
  for (var i=0; i<self.stations.length; i++) {
    window['title' + i].innerHTML = '<b>' + self.stations[i].freq + '</b> ' + self.stations[i].title;
    window['station' + i].addEventListener('click', function(index) {
      var isNotPlaying = (self.stations[index].howl && !self.stations[index].howl.playing());
      
      // Stop other sounds or the current one.
      radio.stop();

      // If the station isn't already playing or it doesn't exist, play it.
      if (isNotPlaying || !self.stations[index].howl) {
        radio.play(index);
      }
    }.bind(self, i));
  }
}
function ( stations ) { var self = this ; self . stations = stations ; self . index = 0 ; // Setup the display for each station. for ( var i = 0 ; i < self . stations . length ; i ++ ) { window [ 'title' + i ] . innerHTML = '<b>' + self . stations [ i ] . freq + '</b> ' + self . stations [ i ] . title ; window [ 'station' + i ] . addEventListener ( 'click' , function ( index ) { var isNotPlaying = ( self . stations [ index ] . howl && ! self . stations [ index ] . howl . playing ( ) ) ; // Stop other sounds or the current one. radio . stop ( ) ; // If the station isn't already playing or it doesn't exist, play it. if ( isNotPlaying || ! self . stations [ index ] . howl ) { radio . play ( index ) ; } } . bind ( self , i ) ) ; } }
Radio class containing the state of our stations.
Includes all methods for playing, stopping, etc.
@param {Array} stations Array of objects with station details ({title, src, howl, ...}).
Radio class containing the state of our stations . Includes all methods for playing stopping etc .