1

I'm making my first steps in coding using online training. For some reasons the code for MP3 player provided in training does not work.

I wrote same code in Brackets and it does not fly. It shows buttons, but when I press them nothing is happening.

Can please someone help me what is the reason for that? Both mp3 file and html file are placed on desktop.

    <html>
    <head>
        <title>Video Player</title>
        <script>
            var player;
        
            window.onload=function()
            {
                player = document.getElementById("sound");
                document.getElementById("btnPlay").addEventListener("click", playMusic, false);
                document.getElementById("btnPause").addEventListener("click", pauseMusic, false);
                document.getElementById("btnStop").addEventListener("click", stopMusic,false);
                }
                function playMusic()
                {
                    player.play();
                }
        
                function pauseMusic()
                {
                    player.pause();
                }
                function stopMusic()
                {
                    player.pause();
                    player/currentTime=0;
                }
    </script>
    </head>
    <body>
        <audio id="sound">
            <source src="mlynarz.mp3" />
        </audio>
        <button id="btnPlay">Play</button>
        <button id="btnPause">Pause</button>
        <button id="btnStop">Stop</button>
     </body>
</html>

2 Answers2

0

If you open the developer console of your browser, in the Console tab you can see there is error Uncaught SyntaxError: Invalid left-hand side in assignment it seems you have a typo in your code player/currentTime=0; it should be player.currentTime=0;.

It will solve the problem. always be careful with the typos.

sajjad rezaei
  • 945
  • 1
  • 10
  • 23
0

Thanks a lot for that one!. It worked. How come Brackets (dev tool I'm using) has not shown that as mistake? Also dev tool in chrome has not pointed mistake here.