Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards compatibility and enabling unit tests for AudioRepository #99

Merged
merged 1 commit into from
Aug 18, 2016

Conversation

gregor
Copy link
Contributor

@gregor gregor commented Aug 18, 2016

Turns out the bug in Karma was new in the latest release already filed and fixed:
karma-runner/karma#2310

I also added backwards compatibility for Firefox for the non Promise based Audio.play()

play_promise.then(_play_success).catch (error) ->
reject new z.audio.AudioError error.message, z.audio.AudioError::TYPE.FAILED_TO_PLAY
else
_play_success()
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a single promise chain like:

Promise.resolve()
.then ->
  if not audio_id or not audio_element
    throw new z.audio.AudioError 'Missing AudioElement or ID', z.audio.AudioError::TYPE.NOT_FOUND
.then ->
  if audio_element.paused
    audio_element.loop = play_in_loop
    audio_element.currentTime = 0 if audio_element.currentTime isnt 0
    return audio_element.play()
  else
    throw new z.audio.AudioError 'Sound is already playing', z.audio.AudioError::TYPE.ALREADY_PLAYING
.catch (error) ->
  throw new z.audio.AudioError error.message, z.audio.AudioError::TYPE.FAILED_TO_PLAY
.then ->
  @currently_looping[audio_id] = audio_id if play_in_loop
  return audio_element

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants