【发布时间】:2021-01-14 11:37:20
【问题描述】:
我在将音频放入我的项目时遇到问题。
我认为thymeleaf src存在源码问题。
<audio id = "player" src = "../../sound/music1.mp3" th:src="@{/sound/music1.mp3}"></audio>
<a onclick = "document.getElementById('player').play()">
<img th:src="@{/img/ic_play_arrow.png}"></a>
<a onclick = "document.getElementById('player').pause()">
<img th:src="@{/img/ic_pause.png}"></a>
<a onclick = "document.getElementById('player').volume += 0.1">
<img th:src="@{/img/ic_volume_up.png}"></a>
<a onclick = "document.getElementById('player').volume -= 0.1">
<img th:src="@{/img/ic_volume_down.png}"></a>
以上代码属于基于片段的。
它被放在这样的视图中:
<div th:insert="fragments/nav :: header"></div>
我的文件结构如下所示:
图片效果很好。
在 Intellij 中通过浏览器打开文件时音频有效。
【问题讨论】:
-
Audio works when file opened by browser in Intellij.这是什么意思?还向我们展示在<audio ..周围的浏览器上生成的 HTML -
欢迎来到 Stack Overflow!寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。见:How to create a Minimal, Complete, and Verifiable example
-
看起来
music1.mp3直接在static目录下,而不是static/sound。
标签: java html spring intellij-idea thymeleaf