简体   繁体   English

播放没有音频标签的音频

[英]Playing audio without audio tag

Is it possible to play audio without the audio tag and just using javascript? 是否可以不使用音频标签而是仅使用JavaScript来播放音频?

I'm injecting script through a tinyMce editor since I don't have access to a site's backend and it doesn't support the audio tag for a client. 我正在通过tinyMce编辑器注入脚本,因为我无权访问网站的后端并且它不支持客户端的音频标签。 She just wants a simple sound when you hover over an image. 当您将鼠标悬停在图像上时,她只想发出简单的声音。 I have it all setup however, the restriction of not having an audio tag is tripping me up. 我已经完成所有设置,但是没有音频标签的限制使我不寒而栗。

I am hosting the audio files on a remote site since I cannot upload them here. 由于无法在此处上传音频文件,因此我将音频文件托管在远程站点上。 Is there perhaps a way to leverage that remote site? 是否有办法利用该远程站点? I've never run into this issue before and can't really find anything on it. 我以前从未遇到过这个问题,也无法真正找到任何东西。

You can use this: 您可以使用此:

mySound = new Audio('sound.mp3');
mySound.play()

Here is a link to its specification - HTMLAudioElement 这是其规范的链接-HTMLAudioElement

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

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