<commit_before>

# Good read: http://html5doctor.com/html5-audio-the-state-of-play/

networkStates =
  0: 'empty'
  1: 'idle'
  2: 'loading'
  3: 'no source'

readyStates =
  0: 'nothing'
  1: 'metadata'
  2: 'current'
  3: 'future'
  4: 'enough'



@mtrPlayer = mtrPlayer = new class MeteorPlayer
  readyState: null
  networkState: null

  audioTag: ->
    $('#player')[0]

  constructor: ->
    Meteor.startup ->
      mtrPlayer.setChannel location.hash.slice(1)

    Meteor.setInterval ->
      if mtrPlayer.audioTag()
        mtrPlayer.checkStatus()
    , 7000

  play: =>
    console.log 'trying to .play()'
    @audioTag()?.play()


  setChannel: (channel) ->
    @readyState = @networkState = null
    Session.set 'channel', ''

    # Attempt at making things more robust
    Meteor.setTimeout (-> Session.set 'channel', channel), 200

    location.href = '#' + channel
    document.title = channel + ' | radio.meteor.com'


  checkStatus: =>
    newNetworkState = @audioTag().networkState
    newReadyState = @audioTag().readyState

    @audioTag().volume = 1

    console.log 'checkStatus net', newNetworkState, @networkState,
          'ready', newReadyState, @readyState,
          'currentTime', @audioTag().duration<commit_msg>not sure<commit_after>

# Good read: http://html5doctor.com/html5-audio-the-state-of-play/

networkStates =
  0: 'empty'
  1: 'idle'
  2: 'loading'
  3: 'no source'

readyStates =
  0: 'nothing'
  1: 'metadata'
  2: 'current'
  3: 'future'
  4: 'enough'


myCL = (l) ->
  _.each l, (msg) ->
    console.log msg


@mtrPlayer = mtrPlayer = new class MeteorPlayer
  readyState: null
  networkState: null

  audioTag: ->
    $('#player')[0]

  constructor: ->
    Meteor.startup ->
      mtrPlayer.setChannel location.hash.slice(1)

    Meteor.setInterval ->
      if mtrPlayer.audioTag()
        mtrPlayer.checkStatus()
    , 7000

  play: =>
    console.log 'trying to .play()'
    @audioTag()?.play()


  setChannel: (channel) ->
    @readyState = @networkState = null
    Session.set 'channel', ''

    # Attempt at making things more robust
    Meteor.setTimeout (-> Session.set 'channel', channel), 200

    location.href = '#' + channel
    document.title = channel + ' | radio.meteor.com'


  checkStatus: =>
    newNetworkState = @audioTag().networkState
    newReadyState = @audioTag().readyState

    @audioTag().volume = 1
    @play()

    myCL ['checkStatus net', newNetworkState, @networkState,
          'ready', newReadyState, @readyState,
          'currentTime', @audioTag().duration]
{'fraction_non_alphanumeric': 0.1449960598896769, 'fraction_numerical': 0.016548463356973995, 'mean_word_length': 2.9242658423493046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714542', 'n_tokens_mistral': 898, 'n_tokens_neox': 841, 'n_words': 190}