tawsif torabi tawsif torabi - 1 year ago 109
HTML Question

How to load only the mp3 file title using javascript?

I've completed the code.It plays the mp3 from user giver url. But it's loading the full url as the title. Is there any way to make it load only the mp3 Title?
I also want it show the title in

tag. I need help.

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"/>
<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>

Answer Source

You can check file extension using this simple code

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

if (url2.match(/.mp3$/g))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download