FileDocCategorySizeDatePackage
AndroidSequencer.javaAPI DocAndroid 1.5 API9450Wed May 06 22:41:02 BST 2009com.android.internal.sound.midi

AndroidSequencer

public class AndroidSequencer extends Object implements Sequencer
Implements a MIDI Sequencer for Android. Since Android's MediaPlayer is somewhat limited, we only support MIDI playback, but not recording or the querying of MIDI information. Many of the methods hence throw {@link java.lang.UnsupportedOperationException} or return dummy results.

Fields Summary
private android.media.MediaPlayer
player
Holds the Android MediaPlayer we use.
private AndroidSequence
sequence
Holds the Android Sequence we want to play.
Constructors Summary
Methods Summary
public int[]addControllerEventListener(javax.sound.midi.ControllerEventListener listener, int[] controllers)

        throw new UnsupportedOperationException();
    
public booleanaddMetaEventListener(javax.sound.midi.MetaEventListener listener)

        throw new UnsupportedOperationException();
    
public voidclose()

        if (isOpen()) {
            stop();
            player = null;
        }
    
public com.android.internal.sound.midi.AndroidSequencer$InfogetDeviceInfo()

        return new Info();
    
public intgetLoopCount()

        throw new UnsupportedOperationException();
    
public longgetLoopEndPoint()

        throw new UnsupportedOperationException();
    
public longgetLoopStartPoint()

        throw new UnsupportedOperationException();
    
public SyncModegetMasterSyncMode()

        throw new UnsupportedOperationException();
    
public SyncMode[]getMasterSyncModes()

        throw new UnsupportedOperationException();
    
public intgetMaxReceivers()

        return 0;
    
public intgetMaxTransmitters()

        return 0;
    
public longgetMicrosecondLength()

        throw new UnsupportedOperationException();
    
public longgetMicrosecondPosition()

        throw new UnsupportedOperationException();
    
public javax.sound.midi.ReceivergetReceiver()

        throw new MidiUnavailableException("No receiver available");
    
public java.util.ListgetReceivers()

        return new ArrayList<Receiver>();
    
public javax.sound.midi.SequencegetSequence()

        return sequence;
    
public SyncModegetSlaveSyncMode()

        throw new UnsupportedOperationException();
    
public SyncMode[]getSlaveSyncModes()

        throw new UnsupportedOperationException();
    
public floatgetTempoFactor()

        throw new UnsupportedOperationException();
    
public floatgetTempoInBPM()

        throw new UnsupportedOperationException();
    
public floatgetTempoInMPQ()

        throw new UnsupportedOperationException();
    
public longgetTickLength()

        throw new UnsupportedOperationException();
    
public longgetTickPosition()

        throw new UnsupportedOperationException();
    
public booleangetTrackMute(int track)

        throw new UnsupportedOperationException();
    
public booleangetTrackSolo(int track)

        throw new UnsupportedOperationException();
    
public javax.sound.midi.TransmittergetTransmitter()

        throw new MidiUnavailableException("No receiver available");
    
public java.util.ListgetTransmitters()

        return new ArrayList<Transmitter>();
    
public booleanisOpen()

        return player != null;
    
public booleanisRecording()

        return false;
    
public booleanisRunning()

        return player != null && player.isPlaying();
    
public voidopen()

        try {
            player = new MediaPlayer();
        } catch (Exception ex) {
            throw new MidiUnavailableException(ex.toString());
        }
    
public voidrecordDisable(javax.sound.midi.Track track)

        throw new UnsupportedOperationException();
    
public voidrecordEnable(javax.sound.midi.Track track, int channel)

        throw new UnsupportedOperationException();
    
public int[]removeControllerEventListener(javax.sound.midi.ControllerEventListener listener, int[] controllers)

        throw new UnsupportedOperationException();
    
public voidremoveMetaEventListener(javax.sound.midi.MetaEventListener listener)

        throw new UnsupportedOperationException();
    
public voidsetLoopCount(int count)

        throw new UnsupportedOperationException();
    
public voidsetLoopEndPoint(long tick)

        throw new UnsupportedOperationException();
    
public voidsetLoopStartPoint(long tick)

        throw new UnsupportedOperationException();
    
public voidsetMasterSyncMode(SyncMode sync)

        throw new UnsupportedOperationException();
    
public voidsetMicrosecondPosition(long microseconds)

        throw new UnsupportedOperationException();
    
public voidsetSequence(java.io.InputStream stream)

        setSequence(new AndroidMidiFileReader().getSequence(stream));
    
public voidsetSequence(javax.sound.midi.Sequence sequence)

        if (!(sequence instanceof AndroidSequence)) {
            throw new InvalidMidiDataException("Sequence must be an AndroidSequence");
        }
        
        if (isRunning()) {
            stop();
        }
        
        this.sequence = (AndroidSequence)sequence;
    
public voidsetSlaveSyncMode(SyncMode sync)

        throw new UnsupportedOperationException();
    
public voidsetTempoFactor(float factor)

        throw new UnsupportedOperationException();
    
public voidsetTempoInBPM(float bpm)

        throw new UnsupportedOperationException();
    
public voidsetTempoInMPQ(float mpq)

        throw new UnsupportedOperationException();
    
public voidsetTickPosition(long tick)

        throw new UnsupportedOperationException();
    
public voidsetTrackMute(int track, boolean mute)

        throw new UnsupportedOperationException();
    
public voidsetTrackSolo(int track, boolean solo)

        throw new UnsupportedOperationException();
    
public voidstart()

        if (!isOpen()) {
            throw new IllegalStateException("Sequencer must be open");
        }
        
        if (sequence == null) {
            throw new IllegalStateException("Need a Sequence to play");
        }

        if (!isRunning()) {
            /*
             * This is ugly, but there is no way around it: The javax.sound API
             * doesn't expect to throw an exception at this point for illegal
             * MIDI sequences. Since we don't really construct the MIDI sequence
             * from the original binary data, but only refer to its URL, the
             * MediaPlayer can actually bail out at this point. We wrap the
             * exception into a RuntimeException, to at least keep the API
             * contract.
             */
            try {
                String s = this.sequence.getURL().toExternalForm();
                
                /*
                 * TODO Workaround for 1107794: MediaPlayer doesn't handle
                 * "file:" URLs. Get rid of this.
                 */
                if (s.startsWith("file:")) {
                    s = s.substring(5);
                }
                
                player.setDataSource(s);
                player.setAudioStreamType(AudioManager.STREAM_MUSIC);
                player.prepare();
            } catch (IOException ex) {
                throw new RuntimeException(ex.toString());
            }
            
            player.start();
        }
    
public voidstartRecording()

        throw new UnsupportedOperationException();
    
public voidstop()

        if (!isOpen()) {
            throw new IllegalStateException("Sequencer must be open");
        }
        
        if (isRunning()) {
            player.stop();
        }
    
public voidstopRecording()

        throw new UnsupportedOperationException();