Basic music player using Bootstrap

Here is an example code that demonstrates how to create a basic music player using Bootstrap:

<!-- HTML for the music player -->
<div id="music-player">
  <audio id="player" controls>
    <source src="music.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
  </audio>

  <div id="music-controls" class="text-center mt-2">
    <button id="previous" class="btn btn-secondary">
      <i class="fas fa-step-backward"></i>
    </button>
    <button id="play-pause" class="btn btn-primary">
      <i class="fas fa-play"></i>
    </button>
    <button id="next" class="btn btn-secondary">
      <i class="fas fa-step-forward"></i>
    </button>
  </div>
</div>

<!-- JavaScript to handle the music player controls -->
<script>
  $(document).ready(function() {
    // Get the audio player element
    var player = $('#player')[0];

    // Handle the play/pause button click
    $('#play-pause').click(function() {
      if (player.paused) {
        player.play();
        $(this).html('<i class="fas fa-pause"></i>');
      } else {
        player.pause();
        $(this).html('<i class="fas fa-play"></i>');
      }
    });

    // Handle the previous button click
    $('#previous').click(function() {
      // Rewind the player by 5 seconds
      player.currentTime -= 5;
    });

    // Handle the next button click
    $('#next').click(function() {
      // Fast-forward the player by 5 seconds
      player.currentTime += 5;
    });
  });
</script>

Note: This is just an example to demonstrate the general approach to creating a music player using Bootstrap. You will need to modify the code to fit your specific requirements and ensure that it follows best practices for error handling and accessibility.

<!-- HTML for the music player -->
<div id="music-player">
  <audio id="player" controls>
    <source src="music.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
  </audio>

  <div id="music-controls" class="text-center mt-2">
    <button id="previous" class="btn btn-secondary">
      <i class="fas fa-step-backward"></i>
    </button>
    <button id="play-pause" class="btn btn-primary">
      <i class="fas fa-play"></i>
    </button>
    <button id="next" class="btn btn-secondary">
      <i class="fas fa-step-forward"></i>
    </button>
    <button id="stop" class="btn btn-secondary">
      <i class="fas fa-stop"></i>
    </button>
    <button id="mute" class="btn btn-secondary">
      <i class="fas fa-volume-up"></i>
    </button>
    <input type="range" id="volume-control" min="0" max="1" step="0.1" value="1">
  </div>
</div>

<!-- JavaScript to handle the customised music player controls -->
<script>
  $(document).ready(function() {
    // Get the audio player element
    var player = $('#player')[0];

    // Handle the play/pause button click
    $('#play-pause').click(function() {
      if (player.paused) {
        player.play();
        $(this).html('<i class="fas fa-pause"></i>');
      } else {
        player.pause();
        $(this).html('<i class="fas fa-play"></i>');
      }
    });

    // Handle the previous button click
    $('#previous').click(function() {
      // Rewind the player by 5 seconds
      player.currentTime -= 5;
    });

    // Handle the next button click
    $('#next').click(function() {
      // Fast-forward the player by 5 seconds
      player.currentTime += 5;
    });

    // Handle the stop button click
    $('#stop').click(function() {
      // Stop the player and reset the time
      player.pause();
      player.currentTime = 0;
      $('#play-pause').html('<i class="fas fa-play"></i>');
    });

    // Handle the mute button click
    $('#mute').click(function() {
      // Toggle the player's mute status
      player.muted = !player.muted;

      if (player.muted) {
        $(this).html('<i class="fas fa-volume-mute"></i>');
      } else {
        $(this).html('<i class="fas fa-volume-up"></i>');
      }
    });

    // Handle the volume control change
    $('#volume-control').on('input', function()

Leave a comment