英文:
How can I add a proper thymeleaf source to my audio file?
问题
<br>
我在我的项目中遇到了放置音频的问题。<br>
我认为问题在于Thymeleaf的src来源。<br>
<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>
上面的代码属于一个基于片段的代码。<br>
它被放置在视图中,如下所示:
<div th:insert="fragments/nav :: header"></div>
我的文件结构如下图所示:
图片工作正常。<br>
在IntelliJ中通过浏览器打开文件时,音频是正常的。
英文:
<br>
I have problem putting audio in my project.<br>
I think that there is a source problem with thymeleaf src.<br>
<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>
The code above belongs to a fragment based.<br>
It is put to views like this:<br>
<div th:insert="fragments/nav :: header"></div>
My files structure looks like this:
Pictures work fine.<br>
Audio works when file opened by browser in Intellij.
答案1
得分: 1
问题解决!
是Spring安全性阻止了/sound文件夹。 <br>
在添加以下内容后:
.antMatchers("/sound/**").permitAll()
音乐播放正常。
英文:
Problem solved!
It was Spring security blocking the /sound folder. <br>
After adding:
.antMatchers("/sound/**").permitAll()
the music plays.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论