播放资产中的音频文件
Play audio-file from assets
我正在尝试播放我放入资产中的歌曲。 (这是路径:app/assets/audios/Jean.mp3),但是我总是在获取请求时出错,我做错了什么?
这是我用来播放文件的代码:
<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>
好的,现在可以了
我已将其添加到辅助文件中:
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>
我正在尝试播放我放入资产中的歌曲。 (这是路径:app/assets/audios/Jean.mp3),但是我总是在获取请求时出错,我做错了什么?
这是我用来播放文件的代码:
<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>
好的,现在可以了
我已将其添加到辅助文件中:
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>