Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>MP3 Player</title>
- <style>
- /* CSS styles for image container */
- .image-container {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- }
- /* CSS styles for image */
- .image-container img {
- width: 200px;
- height: 200px;
- margin: 10px;
- cursor: pointer;
- }
- /* CSS styles for ID3 information container */
- #id3-info {
- margin-top: 20px;
- padding: 10px;
- background-color: #f2f2f2;
- border: 1px solid #ddd;
- display: none;
- }
- /* CSS styles for ID3 information label */
- .id3-label {
- font-weight: bold;
- margin-bottom: 5px;
- }
- /* CSS styles for ID3 information value */
- .id3-value {
- margin-left: 10px;
- }
- </style>
- </head>
- <body>
- <h1>MP3 Player</h1>
- <div class="image-container">
- <img src="song1.jpg" data-src="song1.mp3" data-title="Song 1" data-artist="Artist 1" data-album="Album 1">
- <img src="song2.jpg" data-src="song2.mp3" data-title="Song 2" data-artist="Artist 2" data-album="Album 2">
- <img src="song3.jpg" data-src="song3.mp3" data-title="Song 3" data-artist="Artist 3" data-album="Album 3">
- <img src="song4.jpg" data-src="song4.mp3" data-title="Song 4" data-artist="Artist 4" data-album="Album 4">
- </div>
- <div id="id3-info">
- <div>
- <span class="id3-label">Title:</span>
- <span class="id3-value" id="id3-title"></span>
- </div>
- <div>
- <span class="id3-label">Artist:</span>
- <span class="id3-value" id="id3-artist"></span>
- </div>
- <div>
- <span class="id3-label">Album:</span>
- <span class="id3-value" id="id3-album"></span>
- </div>
- </div>
- <audio id="audio-player" controls></audio>
- <script>
- // JavaScript code for playing audio file when image is clicked
- const images = document.querySelectorAll('.image-container img');
- const audioPlayer = document.querySelector('#audio-player');
- const id3Info = document.querySelector('#id3-info');
- const id3Title = document.querySelector('#id3-title');
- const id3Artist = document.querySelector('#id3-artist');
- const id3Album = document.querySelector('#id3-album');
- images.forEach((img) => {
- img.addEventListener('click', () => {
- const audioFile = img.getAttribute('data-src');
- audioPlayer.src = audioFile;
- audioPlayer.play();
- id3Title.textContent = img.getAttribute('data-title');
- id3Artist.textContent = img.getAttribute('data-artist');
- id3Album.textContent = img.getAttribute('data-album');
- id3Info.style.display = 'block';
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment