如何使用javascript只加载mp3文件标题?

时间:2016-04-30 13:41:26

标签: javascript html html5 html5-audio

我已经完成了代码。它从用户提供者网址播放mp3。但它正在加载完整的网址作为标题。有没有办法让它只加载mp3标题? 我还希望它在<p>标签中显示标题。我需要帮助。

function setAudio() {
    var url = document.getElementById('url').value;
    var audioPlayer = document.getElementById('audioplayer');
    audioPlayer.src = url;
} 

function loadtitle() {
    var title = document.getElementById('url').value;
    var loadtitle = document.getElementById('loadtitle');
    loadtitle.value = title;
}
<center class="lolmanaudio">
    <input type="text" value="Title Here" style="border-width: 1px; border-style: solid; width: 90%; padding: 8px 15px 8px 30px;" id="loadtitle"/>
    <br>
    <button onclick="loadtitle()">Load Title</button>
    <input type="text" id="url"/>
    <button onclick="setAudio()">Load Audio File</button>
    <h5><a href="http://blog.grplusbd.net">GR+ Bangladesh</a></h5>
    <audio id="audioplayer" src="" controls preload="metadata">Your browser does not support the audio element.</audio>
    <br>...
</center>

1 个答案:

答案 0 :(得分:0)

您可以使用此简单代码检查文件扩展名

&#13;
&#13;
var url = "http://example.com/audio/file.mp3";
var url2 = "http://example.com/audio/file.wav";
    
if (url.match(/.mp3$/g))
    alert("mp3");

if (url2.match(/.mp3$/g))
    alert("wav");
&#13;
&#13;
&#13;