2014-02-18 76 views
-1

我想製作一個顯示音樂視頻的網絡應用程序。我創建了一些帶有視頻,播放按鈕,畫布的html,並展示了一些音頻欄和一些名爲「intro」,「verse」和「guitar solo」的標題。javascript中的switch語句問題

我想在歌曲從一個部分跳到另一個部分時在標題之間切換。但是我的switch語句似乎不起作用。我收到第49行的錯誤。

我的Javascript看起來像這樣。

我會很感激在我可以做什麼錯:)

var video = 5; 
var analyser;var canvas; 
var time; 

$(function() { 
    video = $("video")[0]; 
    $("body").on("click", "#playbutton", startStopVideo); 

    createAudioAnalyser(); 
}); 



function createAudioAnalyser() { 
    context = new webkitAudioContext(); 
    analyser = context.createAnalyser(); 
    canvas = $('#soundwave')[0]; 
    ctx = canvas.getContext('2d'); 

    source = context.createMediaElementSource(video); 
    source.connect(analyser); 
    analyser.connect(context.destination); 
} 

function soundAnimation() { 
    window.requestAnimationFrame(soundAnimation); 
    analyser.fftSize = 128; 
    fbc_array = new Uint8Array(analyser.frequencyBinCount); 
    analyser.getByteFrequencyData(fbc_array); 
    ctx.clearRect(0, 0, canvas.width, canvas.height); 
    ctx.fillStyle = 'rgba(0,90,255,0.3)'; 
    bars = 120; 
    for (var i = 0; i < bars; i++) { 
     bar_x = i * 3; 
     bar_width = 2; 
     bar_height = -(fbc_array[i]); 

     ctx.fillRect(bar_x, canvas.height, bar_width, bar_height); 
    } 
} 

//this thing gives an error 
setInterval(function() { 
    myVid = document.getElementById("video"); 
    time = parseInt(myVid.currentTime,10); 
    switch(time) { 
     case 2 
      $("#intro").switchClass("activebox", "inactivebox"); // Here's the error... what is it? 
     break; 
    } 
},1000); 
//--------- 

function startStopVideo() { 

    if(video.paused) { 
     video.play(); 
     soundAnimation(); 
    } else { 
     video.pause(); 
    } 
} 
+1

告訴我們的錯誤將是非常有用(不僅適用於我們,還適用於您)。 –

+0

歡迎使用stackoverflow。每當你使用「我得到一個錯誤」這樣的短語時,把它作爲你的提示立即告訴我們*這個錯誤是什麼*。這將大大增加我們能夠提供幫助的可能性,因爲我們可以立即專注於如何解決問題,而不是必須先弄清楚什麼是錯誤的。 – Chris

+0

您錯過了'case'語句中的冒號(':')。 (查看我的回答) – Cerbrus

回答

4

錯字任何輸入:

case 2 

應該是:

case 2: 
// ^You missed that.