0

別の例からいくつかのコードを取得したサークルメーターゲージで誰かが私を助けることができるかどうか疑問に思っていました.

http://jsbin.com/ixuyid/28/edit

JavaScriptで実行をクリック

以下のコード

var context;

    canvas = document.getElementById('myCanvas');
      context = canvas.getContext('2d');

    //use a reusable function
    function drawCircle(num){
      console.log(num);
      var x = canvas.width / 2;
      var y = canvas.height / 2;
      var radius = 75;
      var startAngle = 0 * Math.PI;
      var endAngle = num * Math.PI;
      var counterClockwise = false;

      context.beginPath();
      context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
      context.lineWidth = 5;

      // line color
      context.strokeStyle = 'black';
      context.stroke();

    }

    drawCircle();

      var num = 1;
      setInterval(function(){

      },1000);

+function(){

  var ctx = new webkitAudioContext()
    , url = '//kevincennis.com/sound/loudpipes.mp3'  
    , audio = new Audio(url)
    // 2048 sample buffer, 1 channel in, 1 channel out  
    , processor = ctx.createJavaScriptNode(2048, 1, 1)
    , meter = document.getElementById('meter')
    , source

  audio.addEventListener('canplaythrough', function(){
    source = ctx.createMediaElementSource(audio)
    source.connect(processor)
    source.connect(ctx.destination)
    processor.connect(ctx.destination)
    audio.play()
  }, false);

  // loop through PCM data and calculate average
  // volume for a given 2048 sample buffer
  processor.onaudioprocess = function(evt){
    var input = evt.inputBuffer.getChannelData(0)
      , len = input.length   
      , total = i = 0
      , rms
    while ( i < len ) total += Math.abs( input[i++] )
    rms = Math.sqrt( total / len )
    meter.style.width = ( rms * 100 ) + '%';
    context.clearRect(100,50,200,200);
    drawCircle(rms);
  }

}()

レベルに問題があるようです???

どんな助けでも

4

1 に答える 1