boyofgreen Posted November 20, 2016 Share Posted November 20, 2016 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? Thanks, Jeff Quote Link to comment Share on other sites More sharing options...
boyofgreen Posted November 21, 2016 Author Share Posted November 21, 2016 also, I don't see a way to play a sound file from a particular point in the audio file. I thought "time" would do that, but it just sets a delay. I want to play the sound 5 seconds into the sound file (think audio sprites). Is there an API for that? Quote Link to comment Share on other sites More sharing options...
boyofgreen Posted November 21, 2016 Author Share Posted November 21, 2016 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; curSound.sound.play(0); } Quote Link to comment Share on other sites More sharing options...
davrous Posted November 21, 2016 Share Posted November 21, 2016 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. Cheers, David gryff 1 Quote Link to comment Share on other sites More sharing options...
davrous Posted November 21, 2016 Share Posted November 21, 2016 By the way, you can set the offset value while calling the play() function like play(0, 20) for an offset of 20. Quote Link to comment Share on other sites More sharing options...
boyofgreen Posted November 22, 2016 Author Share Posted November 22, 2016 today, I do not believe that "play" takes a second parameter, but I'll take a look to make sure. I also have an idea for the change, I'll do a PR and you can look at it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.