Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

A simple HTML5 and JavaScript audio player with play time event listener callback

Posted on April 2, 2025April 2, 2025 by Habibie

In this blog post I will share a snippet for you. It is an HTML5 code with some JavaScript functions in it.

You can play an mp3 audio file while you see a feedback about what seconds is the audio being played. You can modify the code, for example, to show an alert if the audio play time is 10 seconds; and so on.

Here is the script:



Audio Player


Current Time: 0 seconds

<script>
    const audioPlayer = document.getElementById('audioPlayer');
    const currentTimeDisplay = document.getElementById('currentTime');

    audioPlayer.addEventListener('timeupdate', function() {
        const currentTime = Math.floor(audioPlayer.currentTime);
        currentTimeDisplay.textContent = `Current Time: ${currentTime} seconds`;

        if(currentTime == 10){
            alert("It is 10 seconds!");
        }
    });
</script>
Post Views: 294
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme