Mp3 converter
<!DOCTYPE html>
<html>
<head>
<title>MP4 to MP3 Converter</title>
<script>
function convertToMP3() {
// Get the input file and file name
var input = document.getElementById("mp4file");
var fileName = input.value.split("\\").pop();
// Check if the file type is MP4
if (!fileName.endsWith(".mp4")) {
alert("Please select an MP4 file.");
return;
}
// Create an instance of the FileReader
var reader = new FileReader();
// When the FileReader has loaded the file contents
reader.onload = function() {
// Convert the MP4 data to an audio Blob
var audioBlob = new Blob([reader.result], {type: "audio/mp3"});
// Create a URL for the audio Blob
var audioURL = URL.createObjectURL(audioBlob);
// Create a link to download the MP3 file
var downloadLink = document.createElement("a");
downloadLink.href = audioURL;
downloadLink.download = fileName.replace(".mp4", ".mp3");
document.body.appendChild(downloadLink);
downloadLink.click();
}
// Read the input file as an ArrayBuffer
reader.readAsArrayBuffer(input.files[0]);
}
</script>
</head>
<body>
<h1>MP4 to MP3 Converter</h1>
<label for="mp4file">Select an MP4 file:</label>
<input type="file" id="mp4file"><br>
<button onclick="convertToMP3()">Convert to MP3</button>
</body>
</html>
Comments
Post a Comment