在HTML中嵌入标记 - 我如何在Javascript中知道.wav文件已完成播放?

时间:2022-07-23 19:41:26

Right now I'm trying to add a button to a webpage that when pressed will start playing a .wav file by dynamically adding an embed tag to the DOM. The text switches to "Stop" while the sound plays, and I'd like to be able to switch it back automatically to "Play" once the file has finished playing.

现在我正在尝试向网页添加一个按钮,当按下该按钮时,会通过动态地向DOM添加嵌入标记来开始播放.wav文件。当声音播放时,文本切换到“停止”,并且我希望能够在文件播放完毕后自动将其切换回“播放”。

How would I be able to execute some Javascript automatically when the file is finished?

文件完成后,我怎么能自动执行一些Javascript?

Thanks.

3 个解决方案

#1


1  

I would wrap the sound in a very simple flash movie, and use actionscript to trigger a javascript function at the end.

我会将声音包装在一个非常简单的flash影片中,并使用actionscript在最后触发javascript函数。

Here is a list of open-source flash ide : http://osflash.org/open_source_flash_projects

这是一个开源flash ide列表:http://osflash.org/open_source_flash_projects

(That's how google did it in gmail)

(这就是谷歌在gmail中做到的)

#2


1  

Use jPlayer for jQuery, it has an event that triggers when the sound has finished playing.

将jPlayer用于jQuery,它有一个在声音播放完毕后触发的事件。

Requires client-side Flash, but the first Flash players works even when my Firefox Flash-blocker is enabled.

需要客户端Flash,但即使启用了我的Firefox Flash阻止程序,第一个Flash播放器仍可正常工作。

They have several demo players already built.

他们已经建立了几个演示播放器。

#3


0  

If you are embedding a player to play the file (as opposed to just allowing the browser to try to figure what to use on its own (QT, WMP etc.)) then the player should have its own events you can hook into. That depends on the player you use.

如果您正在嵌入一个播放器来播放该文件(而不是仅允许浏览器尝试自己使用什么(QT,WMP等)),那么播放器应该有自己可以挂钩的事件。这取决于你使用的播放器。

#1


1  

I would wrap the sound in a very simple flash movie, and use actionscript to trigger a javascript function at the end.

我会将声音包装在一个非常简单的flash影片中,并使用actionscript在最后触发javascript函数。

Here is a list of open-source flash ide : http://osflash.org/open_source_flash_projects

这是一个开源flash ide列表:http://osflash.org/open_source_flash_projects

(That's how google did it in gmail)

(这就是谷歌在gmail中做到的)

#2


1  

Use jPlayer for jQuery, it has an event that triggers when the sound has finished playing.

将jPlayer用于jQuery,它有一个在声音播放完毕后触发的事件。

Requires client-side Flash, but the first Flash players works even when my Firefox Flash-blocker is enabled.

需要客户端Flash,但即使启用了我的Firefox Flash阻止程序,第一个Flash播放器仍可正常工作。

They have several demo players already built.

他们已经建立了几个演示播放器。

#3


0  

If you are embedding a player to play the file (as opposed to just allowing the browser to try to figure what to use on its own (QT, WMP etc.)) then the player should have its own events you can hook into. That depends on the player you use.

如果您正在嵌入一个播放器来播放该文件(而不是仅允许浏览器尝试自己使用什么(QT,WMP等)),那么播放器应该有自己可以挂钩的事件。这取决于你使用的播放器。