如何将适当的Thymeleaf源代码添加到我的音频文件中?

huangapple go评论105阅读模式
英文:

How can I add a proper thymeleaf source to my audio file?

问题

<br>
我在我的项目中遇到了放置音频的问题。<br>
我认为问题在于Thymeleaf的src来源。<br>

&lt;audio id="player" src="../../sound/music1.mp3" th:src="@{/sound/music1.mp3}"&gt;&lt;/audio&gt;
&lt;a onclick="document.getElementById('player').play()"&gt;
    &lt;img th:src="@{/img/ic_play_arrow.png}"&gt;&lt;/a&gt;
&lt;a onclick="document.getElementById('player').pause()"&gt;
    &lt;img th:src="@{/img/ic_pause.png}"&gt;&lt;/a&gt;
&lt;a onclick="document.getElementById('player').volume += 0.1"&gt;
    &lt;img th:src="@{/img/ic_volume_up.png}"&gt;&lt;/a&gt;
&lt;a onclick="document.getElementById('player').volume -= 0.1"&gt;
    &lt;img th:src="@{/img/ic_volume_down.png}"&gt;&lt;/a&gt;

上面的代码属于一个基于片段的代码。<br>
它被放置在视图中,如下所示:

&lt;div th:insert="fragments/nav :: header"&gt;&lt;/div&gt;

我的文件结构如下图所示:

如何将适当的Thymeleaf源代码添加到我的音频文件中?

图片工作正常。<br>
在IntelliJ中通过浏览器打开文件时,音频是正常的。

英文:

<br>
I have problem putting audio in my project.<br>
I think that there is a source problem with thymeleaf src.<br>

&lt;audio id = &quot;player&quot; src = &quot;../../sound/music1.mp3&quot; th:src=&quot;@{/sound/music1.mp3}&quot;&gt;&lt;/audio&gt;
        &lt;a onclick = &quot;document.getElementById(&#39;player&#39;).play()&quot;&gt;
            &lt;img th:src=&quot;@{/img/ic_play_arrow.png}&quot;&gt;&lt;/a&gt;
        &lt;a onclick = &quot;document.getElementById(&#39;player&#39;).pause()&quot;&gt;
            &lt;img th:src=&quot;@{/img/ic_pause.png}&quot;&gt;&lt;/a&gt;
        &lt;a onclick = &quot;document.getElementById(&#39;player&#39;).volume += 0.1&quot;&gt;
            &lt;img th:src=&quot;@{/img/ic_volume_up.png}&quot;&gt;&lt;/a&gt;
        &lt;a onclick = &quot;document.getElementById(&#39;player&#39;).volume -= 0.1&quot;&gt;
            &lt;img th:src=&quot;@{/img/ic_volume_down.png}&quot;&gt;&lt;/a&gt;

The code above belongs to a fragment based.<br>
It is put to views like this:<br>

&lt;div th:insert=&quot;fragments/nav :: header&quot;&gt;&lt;/div&gt;

My files structure looks like this:

如何将适当的Thymeleaf源代码添加到我的音频文件中?

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(&quot;/sound/**&quot;).permitAll()

the music plays.

huangapple
  • 本文由 发表于 2020年9月29日 05:19:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/64109771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定