Detect whether or not there is anything MIDI playing. - Java javax.sound.midi

Java examples for javax.sound.midi:MidiSystem

Description

Detect whether or not there is anything MIDI playing.

Demo Code


//package com.java2s;

import javax.sound.midi.Sequencer;

public class Main {
    static Sequencer sequencer;

    /**/*ww w .jav  a  2s . c  o m*/
     * Detect whether or not there is anything playing.
     */
    public static boolean isPlaying() {
        try {
            if (sequencer == null) {
                return false;
            }

            // if it is not open, then it's not playing
            if (!sequencer.isOpen()) {
                return false;
            }

            return sequencer.isRunning();

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
            return false;
        }
    }
}

Related Tutorials