Giter VIP home page Giter VIP logo

Comments (7)

ShiiRochi avatar ShiiRochi commented on May 23, 2024 1

So, you can subscribe to "audioprocess" event and it's working, but it does not work with "finished", don't you?

If that is so, then event subscription through wavesurfer instance is working, however finished event is not being fired for some reason that is, from my POV, wavesurfer.js related.

Also, it may be, that "finished" is called after record is played up to the end.

from wavesurfer-react.

ShiiRochi avatar ShiiRochi commented on May 23, 2024 1

@Simoneth, I've tried to listen for "finish" event in demo fork.

The result is that this event is called when record playing is fully completed, it is not related to region or region play, because all you do to play region is just like make wavesurfer to play record's fragment, when "finish" is related to record.

It should also be taken into account, that the end of an audio can differ from the end of a region, so even if there would be a difference in a pair of milliseconds, then "finish" can be not fired...but this is just my assumption.

from wavesurfer-react.

ShiiRochi avatar ShiiRochi commented on May 23, 2024 1

@Simoneth, I think, that this question (how to listen to region play completed or simulate it) is more related to wavesurfer.js repository. From my point of view, you can add a new listener for...audioprocess or progress event (I don't remember all the list), but with explicit aim to call some callback when progress will reach region's end...I will provide you with some pseudo code, but the rest is fully up to you:

function callbackFn () {
    ...some code...
} // or useCallback...

// It will save you from referencing issues withing listeners
const callbackRef = useRef(callbackFn);

function playRegion ({ start, end, ...restOfRegion }) {
    ws.current.on("progress", (data) => {
        if (data === end) {
            callbackRef.current();
        }
    });

    ws.current.play(
      start,
      rend
    );
}

from wavesurfer-react.

ShiiRochi avatar ShiiRochi commented on May 23, 2024

@Simoneth, hi, did you try to check whether other events are being fired?

from wavesurfer-react.

Simoneth avatar Simoneth commented on May 23, 2024

@Simoneth, hi, did you try to check whether other events are being fired?

Hmm...it's strange, I can fire "audioprocess" but not "finish" and I have no idea why.
This is my function to start play, maybe it's related (I use regions):

   wavesurferRef.current.play(
      regionsRef.current[id].start,
      regionsRef.current[id].end
    );

from wavesurfer-react.

Simoneth avatar Simoneth commented on May 23, 2024

@Simoneth, I've tried to listen for "finish" event in demo fork.

The result is that this event is called when record playing is fully completed, it is not related to region or region play, because all you do to play region is just like make wavesurfer to play record's fragment, when "finish" is related to record.

It should also be taken into account, that the end of an audio can differ from the end of a region, so even if there would be a difference in a pair of milliseconds, then "finish" can be not fired...but this is just my assumption.

Since I use only regions, from Regions plugin page, I can't find any event that could fire the end of the region play...any workaround? It's just for my toggle button "Play / Stop"

from wavesurfer-react.

Simoneth avatar Simoneth commented on May 23, 2024

Here my simple solution:

    useEffect(() => {
        wavesurferRef.current.on("region-out", () => {
            console.log("Track Finished");
        });
    }, [regions]); 

from wavesurfer-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.