2014-03-28 63 views
0

在我的應用程序,用戶可以按下「開始記錄」記錄了這個按鈕如何重播的用戶輸入與touchstart和touchend

<div class="drum" id="bass" ontouchstart="play('bass');" ontouchend="touchEnd(event);">Bass</div> 

,然後保存這些信息到一個數組

[{"time":918,"elemId":"bass"},{"time":1326,"elemId":"highhat"}] 

然後,我如何重播這些信息來觸發ontouchstart和ontouchend事件?基本上模仿用戶輸入。

+0

你最好叫功能而不是僞造事件 – rupps

+0

我該如何去做到這一點?我嘗試了一切似乎,現在只是讓人沮喪 – user3464627

回答

0

你要像...

var NOTES=[{.....}], 
    mCurrentNote=0, 
    mStartTimer=0, 
    mTimerId, 
    mNextNote=null, 
    SPEED=100; // speed in ms 

// gets the next note 

function get_next_note() { 
     return NOTES[mCurrentNote++] || null; 
} 

function timer() { 
    // this gets called every SPEED ms 
    if (mNextNote==null) mNextNote=get_next_note(); 
    if (mNextNode!=null) { 
      var playhead=new Date.valueOf()-mStartTime; 

      if (playhead < mNextNote.start) return; 

      window.setTimeout(function() {play (mNextNote.type);},1); 

    } else { 
      window.clearInterval (mTimerId); 
      // song finish 
    } 

} 

function playsong() { 
    mCurrentNote=0; 
    mStartTime=new Date.valueOf(); 
    mTimerId=window.setInterval (timer, SPEED); 
} 

不過我建議你,如果你打算做一些半認真的去看看http://www.html5rocks.com/en/tutorials/webaudio/intro/#toc-abstract ......

相關問題