Jump to content

finding duration of sound file and see if it shoudl be playing


Recommended Posts

Hi. I remember meeting a French guy who was very close with his brother (he talked about him a lot) and worked on the audio for Babylon.js.  I have a question for him.

I am looking at my audio files and trying to determine if they should be playing at any particular keyframe based on them being set to Play at an earlier key frame.  Right now I'm looking at the soundFile._audioBuffer.duration and then doing some math to determine if it should be playing part way through at the current key frame.  Two questions:

1. is there an easier way to do this?

2. is the "duration" accurate or is there a better way to get duration of a sound file?




Link to comment
Share on other sites

Right now I am using the following to make this work  (item is the key where the file started in the past, keyIndex is my index tracking, kps is 60)

  if(item < keyIndex){
      var audioEndKeyFrame = item+(Math.round(curSound.sound._audioBuffer.duration)*kps);
      if(audioEndKeyFrame > keyIndex){
        var keyFramePlayPoint = (keyIndex-item)/kps;
        curSound.sound.isPaused = true;
        curSound.sound._startOffset = keyFramePlayPoint;


Link to comment
Share on other sites

Hi Jeff,

 Good feedback. Yes, audioBuffer.duration is accurate. It's not the first time I've been asked to implement Sprite on audio, I'll work on that. If you have a prefered way or idea on how the API should look as the client caller, I'll be interested. 

 I'm going to expose the duration as a public property also. 



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...