我试图播放一首我投入资产的歌曲。 (这是路径:app / assets / audios / Jean.mp3),但我总是在get-request上收到错误,我做错了什么?
这是我用来播放文件的代码:
<button onclick="playAud()" type="button">Play</button>
<audio id = "audio" autoplay>
<source src= 'app/assets/audios/jean.mp3' type="audio/mpeg">
</audio>
<script>
var audio = document.getElementById("audio");
function playAud() {
audio.play();
}
</script>
答案 0 :(得分:1)
好的,现在可行了
我已将此添加到帮助文件中:
def audio_path(source, options = {})
path_to_asset(source, {type: :audio}.merge!(options))
end
并将视图文件中的代码更改为:
<audio src="<%= audio_path 'jean.mp3'%>" type="audio/mpeg" controls>
Your browser does not support the audio element.
</audio>