简体   繁体   English

将音频同步到图片转盘

[英]sync audio to a picture carrousel

Is it possible to sync audio to a picture carrousel without using the canvas? 是否可以在不使用画布的情况下将音频同步到图片转盘? Im currently using setInterval to realize the carrousel. 我目前正在使用setInterval来实现旋转木马。 I dont want to use flash and if possible and not too hard to realize, I want to do this without the canvas. 我不想使用Flash,并且如果可能且不太难实现,我希望在没有画布的情况下执行此操作。

Have you tried a canvas? 你尝试过画布吗?

Assuming you're using an <audio> element, you can get its currentTime property. 假设您正在使用<audio>元素,则可以获取其currentTime属性。 This will tell you where the playhead is. 这将告诉您播放头在哪里。 You can use this information to change the carousel when the audio passes a certain position, or you can set it to change the audio position when the carousel changes. 您可以使用此信息在音频通过某个位置时更改转盘,或者可以设置为在转盘更改时更改音频位置。 Whatever works better for what you're doing. 无论哪种方式都能更好地满足您的工作需求。

What do you mean by realize the carousel? 意识到轮播是什么意思?

I would set a specific timestamp when you want the image to show. 当您要显示图像时,我将设置特定的时间戳。 So at 12 seconds you want to show image. 因此,您想在12秒后显示图像。

You might want to also make sure that the audio is loaded. 您可能还需要确保已加载音频。 You can use canPlayThrough to check and see if enough is loaded to play through or you can use audio.buffered.end(0) to check against the length of the audio file and make sure the entire thing has loaded. 您可以使用canPlayThrough来检查并查看是否加载了足够的canPlayThrough以进行播放,也可以使用audio.buffered.end(0)来检查音频文件的长度并确保已加载整个内容。

Here is a good article for more on this: http://html5doctor.com/html5-audio-the-state-of-play/ 这是一篇很好的文章,内容更多: http : //html5doctor.com/html5-audio-the-state-of-play/

When the audio is loaded you call a function and pass in the timestamp and set it as the setInterval time. 加载音频后,您将调用一个函数并传入时间戳并将其设置为setInterval时间。 So at timestamp * 1000 the function will fire and show the image that is passed at that timestamp. 因此,在timestamp * 1000该函数将触发并显示在该时间戳处传递的图像。

You could also try and use audio.currentTime and fire then, more on that in the article above as well. 您还可以尝试使用audio.currentTime并触发,然后在上面的文章中对此进行更多介绍。 Let me know if you have a more specific question. 让我知道您是否还有更具体的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM