Find the current elapsed time using Wavesurfer in real time

I am currently utilizing the waveSurfer library created by katspaugh for playing audio files.

In order to display 'elapsed time / total time', I have written code in the following manner:

waveSurfer.on('play', function() {
   $scope.getCurrentDuration();
});

The $scope.getCurrentDuration() function is designed to convert a floating-point variable into a string, as shown below:

$scope.getDuration = function() {

  if ($scope.waveSurferReady) {
    var time = waveSurfer.getDuration(); 
    var minute = Math.floor(time / 60); 
    var tmp = Math.round(time - (minute * 60)); 
    var second = (tmp < 10 ? '0' : '') + tmp; 

    return String(minute + ':' + second); 
  }

  else {
    return 'not ready yet'; 
  }
};

However, I am facing an issue. When it comes to this part:

waveSurfer.on('play', function() ...)
the callback function is only triggered once.

I was expecting the callback function to be called periodically, but it seems to execute only once, resulting in the elapsed time being displayed only at the beginning.

How can I go about resolving this?

Answer №1

After delving into the codebase, I came across the audioprocess event along with the html5 timeupdate event.

Give it a try.

waveSurfer.on('audioprocess', function() {
   // do something here
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method for calculating the total of a mongoose attribute?

I am attempting to calculate the sum of schema using reduce. However, the current code is not adding the items together but rather placing them next to each other. For example, 20 + 30 should result in 50, but instead it gives me 02030. Is there an issue w ...

Embed the json data within the modal box

I received a JSON response from a php function, and it looks like this: [{"id":"15","activity_type":"call","activity_title":"Call to check "}] Below is the script that triggers the request (actvitiy.js) (Edited) $(document).on("click", ".view_contact_ac ...

I am attempting to use $.map to transfer values into a new array, but unfortunately, it is not producing the desired result

This task seems easy at first glance, but unfortunately it's not working for me. Can someone please point out what I might be doing wrong? var oldArr = [0, 1, 2]; var newArr = []; /* * This function is supposed to add 1 to each element in the array ...

What is the best way to handle a $q.when promise in unit testing?

Currently, I am utilizing $q.when to transform promises from third-party sources, specifically those returned by PouchDB, into Angular promises. Here is the scenario: 'use strict'; angular.module('test', []) .service('pouchdb&a ...

Tips for accessing the parent reference while binding using the .on() method

I needed to attach an event like this $("div").on("click", "li",function() { var div= $(this).parent().parent(); //this is what i'm using //..... }); above the <div> <ul> <li>1</li> <li>e2</l ...

Arranging titles on the top of the page in a column format, resembling an index

Has anyone figured out how to make the title of the content stick at the top, one below the other, as the user scrolls? I've been using Bootstrap's Scrollspy, which works fine, but I need a few additional features. You can check out the codepen l ...

I am attempting to utilize diagram.highlightCollection in gojs to showcase nodes that do not meet a specific condition

I have a list of node IDs (keys) and I need to highlight those nodes. For empty nodes, the same condition works fine. For example: checkEmptyNodes() { const emptyNodes = []; const diagDetails = this.myserv.getDiagramData(); ...

"I have successfully removed the URL from index.html. However, I am now wondering how I can include them in app

I have modified the URL in index.html to remove query parameters, but now I need my app.component.ts file to still be able to access and work with those query params using ActivatedRoute. However, when I implemented the script in index.html to remove query ...

Attempting to transfer user information to MongoDB using AngularJS and Node.js

Greetings everyone! I am currently working on a template and trying to develop a backend for it, starting with the registration form. Despite having some kind of connection between my mongodb and my app, data is not being sent to the database. Here is the ...

Comparing Dates in Node.js using JavaScript and Sorting Arrays based on Date Values

Is JavaScript lacking a basic Date comparison feature similar to Python? Within my Node.js script, these lines are present: console.log(Date(2012,11,10) < Date(2012, 11, 9)) console.log(Date(2012,11,10) > Date(2012, 11, 9)) Surprisingly, both of t ...

Combining arrays of arrays within AngularJS

I recently came across this controller code on Stack Overflow, which I have modified slightly. var getData = function() { var swindon = $http.get('(url)/swi/10?expand=true'), paddington = $http.get('(url)/pad/10?expand=t ...

Automatically add values after successful Facebook login

Currently, I am working on a Cordova project where I have implemented Facebook login for user authentication. While the login is functioning correctly, I am facing an issue where I need to manually press a button with the ID getinfo in order for the values ...

Sorting by number or date in indexedDB may lead to unexpected results due to the

I have set up an index in my database called time on the created_at field: var os = thisDB.createObjectStore(name, { keyPath : "id" }); os.createIndex("time", "created_at", {unique: false }); Instead of storing the time as a standard date format, I conv ...

How can I create a unique CSS or JS transition for a button that dynamically changes size based on text

My Angular app features a button labeled with "+". When the user hovers over it, I use element.append(' Add a New Number'); to add the text "Add a New Number" next to the + sign in the label. Upon clicking the button, a new number is added and ...

Code written in JQuery functions correctly when executed within the console, yet encounters issues when located within the script tag or

I'm attempting to build an online drawing tool reminiscent of an Etch-A-Sketch by using a grid of div elements. However, I'm facing an issue where the code responsible for highlighting the boxes when the mouse hovers over them (using the mouseent ...

How to incorporate a custom JavaScript file into an Angular 7 application

Suppose there is a JavaScript file named mylib.js in an angular 7 application, located at assets/mylib.js: mylib = function(){ return { hi: function() { alert('hi'); } }; }(); If I want to be able to call mylib.hi() in my hero-f ...

Updating a class within an AngularJS directive: A step-by-step guide

Is there a way to change the class (inside directive) upon clicking the directive element? The current code I have updates scope.myattr in the console but not reflected in the template or view: <test order="A">Test</test> .directive("test", ...

How come the mongoose ref feature is not functioning properly for me when I attempt to reference objects from a different schema?

I'm having trouble accessing the attributes of a store's address, as I keep getting 'undefined'. It seems that the address is only an id, even though I set up a 'ref' in the address schema. What could be causing this issue? H ...

Design a four-room apartment layout using three.js technology

My goal is to design a model of an apartment with four rooms. https://i.sstatic.net/3gPpG.jpg To achieve this, I have created a transparent cube to represent one room, but now I am facing challenges in adding the other three sections. https://i.sstatic. ...

Is there a way to extract both a and b from the array?

I just started learning programming and I'm currently working on creating an API call to use in another function. However, I've hit a roadblock. I need to extract values for variables a and b separately from the response of this API call: import ...