2013-06-30 63 views
3

我嘗試使用下面的方法來創建視頻可視化(最少的代碼只是爲了看看可能性):如何從視頻元素獲得頻率數據,並饋入音頻API在飛行

HTML:

<canvas id=canvas width=427 height=240></canvas> 

JS:

var context = new webkitAudioContext() 
    , analyser = context.createAnalyser() 
    , video = document.createElement('video') 
    , source = context.createMediaElementSource(video) 
    , canvas = document.getElementById('canvas') 
    , ctx = canvas.getContext('2d') 
    ; 

var loadVideos = function() { 
    video.src = 'my video.ogg'; 
    source.connect(analyser); 
    analyser.connect(context.destination); 

    video.play(); 
    videoVisualization(); 
} 
loadVideos(); 

function videoVisualization() { 
    window.webkitRequestAnimationFrame(videoVisualization); 
    ctx.drawImage(this.video, 0, 0, canvas.width, canvas.height); 

    var freqByteData = new Uint8Array(analyser.frequencyBinCount); 
    analyser.getByteFrequencyData(freqByteData); 

    for (i = 0; i < freqByteData.length; ++i) { 
     console.log(freqByteData[5]); 
    } 
} 

這可以很容易做,如果我在添加此0

特別是當我用scriptProcessor Node獲取音頻數據時,但我想動態改變視頻源,而視頻標籤不支持它。

在此先感謝,

回答

0

Chromecast不完全支持Web音頻。頻率數據是不支持的事情之一。檢查bug here