Jump to content
Search Community

Linking soundbite to timeline

payne199 test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I am looking to add a soundbite to my timeline. By all appearances (to me) the codepen I included should do it.  

   I have created the audio element.

   I have added it as a function to the timeline.

But it will not play.

Would someone shed some light on this dilema for me?

Thank you. 

(A great soundbite, huh?)

See the Pen QWLYeMz by don199 (@don199) on CodePen

Link to comment
Share on other sites

Hey Payne,

 

That soundbite played immediately when I opened this page (quite loudly), hah. So yes, it does work. My guess is that it's a conflict with CodePen. Or the fact that it auto-plays (some browsers try to prevent that). Or maybe that the file is not done loading by the time it's supposed to play.

 

What's your end goal?

Link to comment
Share on other sites

2 hours ago, payne199 said:

(A great soundbite, huh?)

 

Yep.

 

See the Pen epLjrG by osublake (@osublake) on CodePen

 

 

1 hour ago, ZachSaucier said:

Or maybe that the file is not done loading by the time it's supposed to play.

 

That's probably the issue. loading starts whenever you set the source, which you're doing inside your function, so it won't play immediately unless it's cached. 

 

  • Like 2
Link to comment
Share on other sites

Hi Guys. Yeah I see it plays here, without any problem, but not on my machine. I tried just using a simple typewriter 'ding' to sound, and that doesn't go either. Perhaps it IS due to auto-play. What I am wanting to do, ultimately, is construct a 5-minute video for a friend's 40th bday. Although this simply tween does not show this in any way. Can you offer me advise as to how to load the sound first? To try that angle? (Blake, Craig. I thought you guys would get a kick out of that!).

Link to comment
Share on other sites

Thanks for the info, guys. I have decided to run with a button to start things off and have updated the codepen to reflect that. On initial play, the sound is always delayed compared to the image coming on the screen. But after that first run, it will always run correctly, in sync. But of course, if I were to back-out of the page completely and go in again, the initial run will be out of sync. I looked for a similar problem in the forum but did not find one. Could you explain to me why this is occuring? The initial run has to be on the money.

Link to comment
Share on other sites

1 hour ago, payne199 said:

On initial play, the sound is always delayed compared to the image coming on the screen.

 

Did you look at the demos Zach and I made? The delay happens because you are loading the audio source in the function. It's not going to load until the function is called, thus causing a delay.

 

But this really isn't a GSAP question. It has to do with audio and media APIs.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement

https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio

 

You need to make sure the audio is loaded or can at least play through before starting your timeline. This enables the play button once the audio can play through.

 

See the Pen 3d026b6fcd95fc1e2fa155a02664cdef by osublake (@osublake) on CodePen

 

 

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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