8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

webkitAudioContextからAudioContextに変更

Last updated at Posted at 2014-08-03

chrome36?からWeb Audioの仕様が変わったようなのでとりあえず動くコードのメモ
http://updates.html5rocks.com/tag/webaudio

audio.coffee
# https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Porting_webkitAudioContext_code_to_standards_based_AudioContext#Removal_of_the_synchronous_AudioContext.createBuffer_method

# webkit以外も動くように
window.AudioContext = window.AudioContext || window.webkitAudioContext
context = new AudioContext()
src = context.createBufferSource()
gain = context.createGain()   # createGainNode()から変更
analyserNode = context.createAnalyser()
analyserNode.connect(context.destination)
src.connect(gain)
gain.gain.value = 0.85
gain.connect analyserNode
_analyzedData = new Uint8Array(analyserNode.frequencyBinCount)

play = ->
  context.decodeAudioData request.response, (onSuccess = (decodedBuffer) ->
    # bufferはcallback内に変更
    src.buffer = decodedBuffer
    src.start(0) #noteOn()から変更
  ), onFailure = -> console?.info "Decoding the audio buffer failed"

# 再生用
request = new XMLHttpRequest()
url = "some/audiodata.mp3"
request.open "GET", url, true
request.responseType = "arraybuffer"
request.onload = -> play()
request.send()

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?