2011-08-08 4 views

答えて

3

私はplayイベントを処理し、完了したらsetTimeoutコールトラックを使用します。このようなもの(擬似コード):

var timeHandler = null; 

// if they stop listening, don't give them the alert 
    myAudioElement.addEventListener('stop', function() { 
    if (timeHandler) clearTimeout(timeHandle); 
    }); 

// when they start to play, set an event to pop up 5 seconds later 
    myAudioElement.addEventListener('play', function() { 
     timeHandler = setTimeout(5000,function() { 
      // here I would make some kind of ajax call to log the event 
      alert("it's been 5 seconds!"); 
     }); 

いつものように、これは必要に応じてはるかに複雑になる可能性があります。また、ontimeupdateイベントを使用して、再生ヘッドが現在座っている場所を追跡することもできます。

https://developer.mozilla.org/en/DOM/Media_events

幸運:HTML5オーディオイベントのリファレンスについては、このページをチェックしてください!

+0

' 'play''イベントの後に遅延があり、実際にオーディオが再生を開始することがあります。 '' timeupdate''にイベントリスナーを設定する方が安全です。 – mzedeler

関連する問題