gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
html tone.js mp3 loop
- User
html tone.js mp3 loop
- Assistant
To create a simple HTML page that uses Tone.js to play an MP3 file in a loop, you can follow the example code below. This code will initialize Tone.js and load an MP3 file. It will then play the sound in a loop when a button is clicked.
Example HTML Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>MP3 Loop with Tone.js</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.36/Tone.js"></script> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; } button { padding: 10px 20px; font-size: 16px; } </style> </head> <body> <button id="playButton">Play Loop</button> <script> // Create a player instance const player = new Tone.Player("path/to/your-sound.mp3", { loop: true, // Loop the sound }).toDestination(); // Function to start playback document.getElementById("playButton").addEventListener("click", async () => { // Ensure that the audio context is started await Tone.start(); console.log("Audio context started"); // Start the player player.start(); }); </script> </body> </html>