There is a community extension which lets users upload URLs to sprites. Is it possible that I would be able to upload audio files? I need it for a feature in my rhythm game.
Thanks for the help!
There is a community extension which lets users upload URLs to sprites. Is it possible that I would be able to upload audio files? I need it for a feature in my rhythm game.
Thanks for the help!
I have javascript code for importing mp3 and wav if you want.
Would you be able to share it?
function convertAudioToBase64(event) {
// Create a file input element
const input = document.createElement('input');
input.type = 'file';
// Restrict file selection to MP3 and WAV audio files
input.accept = 'audio/mpeg, audio/wav';
// Trigger the file selection when the event is fired
input.click();
// When the user selects a file
input.onchange = function() {
const file = input.files[0];
if (file) {
// Check if the file is either MP3 or WAV
if (file.type === 'audio/mpeg' || file.type === 'audio/wav') {
const reader = new FileReader();
// When the file is read successfully, convert it to Base64
reader.onload = function(e) {
// `e.target.result` contains the Base64 string
const base64String = e.target.result;
// Access the scene and set the Base64 string in a scene variable
// Assuming you already have a scene variable called "Temp"
runtimeScene.getVariables().get("Temp").setString(base64String);
// Log the Base64 string to the console (optional)
console.log(base64String);
};
// Handle any errors during reading
reader.onerror = function(error) {
console.error("Error reading file:", error);
};
// Convert the file to a Base64 string
reader.readAsDataURL(file); // This starts the Base64 conversion
} else {
console.error('Please select an MP3 or WAV file.');
}
}
};
}
// Call the function to trigger the file input and conversion
convertAudioToBase64();
This script import a Mp3 or wav and converted it to Base64 but I am working on a Game now. TerraCraft-Template
Thank you very much!