locked
How to Pause background music from playing RRS feed

  • Question

  • User1016820894 posted

    I have an asp.net application where music plays automatically when the page loads (see code below). One of the options on the page, when clicked, will open a new page in a new window. In that window there is a video that plays. The problem is that the background music is playing along with the sound from the video. I need a way to pause the background music for about 3 minutes while the video plays. How would I accomplish that?

    Code upon page load:

      <div id="audio_playMain">
                <audio id="audio_file_main" autoplay loop runat="server">
      <source src="/Images/Just_Feeling_Great_full_mix.mp3" type="audio/mpeg">
    </audio>  

    Tuesday, February 11, 2020 3:01 PM

All replies

  • User288213138 posted

    Hi baldwinjohn,

    I need a way to pause the background music for about 3 minutes while the video plays. How would I accomplish that?

    You can use the pause() method pauses the currently playing audio. then use the setTimeout() method to set time for pause.

    <script>         
            function pause() {
                var x = document.getElementById("audio_file_main"); 
                x.pause();
                setTimeout(function () {
                    x.play();
                }, 5000);   // wait 5 second
            }
        </script>

    Best regards,

    Sam

    Wednesday, February 12, 2020 4:42 AM
  • User-857013053 posted

    function pauseBackgroundMusic() {
    var beepTwo = $("#musicBeat");
    if (beepTwo[0].paused == false) { beepTwo.animate({volume: 0}, 2000, 'swing', function() { // really stop the music beepTwo[0].pause(); }); 

    Saturday, February 22, 2020 5:01 AM