Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hook to implemet a call back when a sample is over #1

Open
ghost opened this issue Apr 24, 2010 · 1 comment
Open

hook to implemet a call back when a sample is over #1

ghost opened this issue Apr 24, 2010 · 1 comment
Milestone

Comments

@ghost
Copy link

ghost commented Apr 24, 2010

think will be useful a call back system to use to detect when a sample/snipet/sond is ended

@ddf ddf added this to the 3.0.0 milestone Jan 5, 2015
@MeFisto94
Copy link

import ddf.minim.spi.AudioRecordingStream;
import ddf.minim.ugens.FilePlayer;

public class ListenableFilePlayer extends FilePlayer {
    Runnable listener;
    public ListenableFilePlayer(AudioRecordingStream iFileStream, Runnable listener) {
        super(iFileStream);
        this.listener = listener;
    }

    @Override
    protected void uGenerate(float[] channels) {
        boolean wasPlaying = isPlaying();
        super.uGenerate(channels);
        if (wasPlaying && !isPlaying()) {
            listener.run();
        }
    }
}

Just in case someone is needing this, that's the example I put together. It is called Listener because ideally the Runnable is extended to have some "onStart(), onPause(), onResume() and onFinished()" or something. Also note that I'm not certain how good my approach is, but I guess the only way that the play status changes between uGenerate approaches are when the sample has been finished or a problem occured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants