public class Player
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Player.MediaPlayerState
The state of the MediaPlayer
there is a chart of these states in the MediaPlayer documentation
|
static class |
Player.PlayerException
An exception from the Player
|
static class |
Player.State
the state of the Player
|
Constructor and Description |
---|
Player(SScore score,
UserTempo userTempo,
android.content.Context context,
boolean playNotes,
PlayData.PlayControls playControls) |
Player(SScore score,
UserTempo userTempo,
android.content.Context context,
boolean playNotes,
PlayData.PlayControls playControls,
int startLoopBarIndex,
int endLoopBarIndex,
int numRepeats)
Construct the Player
|
Modifier and Type | Method and Description |
---|---|
int |
bestScrollAnimationTime()
get a value to use for the scroll animation so it scrolls faster for a fast score
|
int |
currentBar()
the bar which was last dispatched
|
int |
minBarDuration()
get the duration of the shortest bar
|
boolean |
needsFastCursor()
min bar time of less than 2s requires fast cursor
We use this to disable the note cursor which takes a lot of processing and can fill up the event queue
faster than it can be emptied
|
void |
pause()
pause play and dispatch
|
void |
reset()
stop playing and reset to start
|
void |
resume(boolean countIn)
resume from the start of the current bar after pause (with count-in)
|
void |
setBarStartHandler(Dispatcher.EventHandler handler,
int delay_ms)
set the handler to be called on each bar start
|
void |
setBeatHandler(Dispatcher.EventHandler handler,
int delay_ms)
set the handler to ba called on each beat
|
void |
setEndHandler(Dispatcher.EventHandler handler,
int delay_ms)
set the handler to be called at end of play (not on stop)
|
void |
setNoteHandler(Dispatcher.NoteEventHandler handler,
int delay_ms)
set the handler to be called for each note or chord as it is played
|
void |
startAt(int barIndex,
boolean countIn)
start playing and dispatching handlers from the given bar with optional count-in
|
Player.State |
state()
the current Player.State
|
void |
updateMedia() |
void |
updateTempo()
notification that the tempo has changed (eg when the user has changed a tempo slider)
Everything is stopped and restarted at the start of the current bar with the new tempo
|
public Player(SScore score, UserTempo userTempo, android.content.Context context, boolean playNotes, PlayData.PlayControls playControls, int startLoopBarIndex, int endLoopBarIndex, int numRepeats) throws Player.PlayerException
score
- the score to playuserTempo
- access to UI (eg slider) which defines the tempocontext
- the context (eg MainActivity)playNotes
- true to use the MediaPlayer to play the notes, else it dispatches events silentlyPlayer.PlayerException
- on errorpublic Player(SScore score, UserTempo userTempo, android.content.Context context, boolean playNotes, PlayData.PlayControls playControls) throws Player.PlayerException
Player.PlayerException
public void updateMedia()
public int minBarDuration()
public boolean needsFastCursor()
public int bestScrollAnimationTime()
public int currentBar()
public void reset()
public void updateTempo() throws Player.PlayerException
Player.PlayerException
- on errorpublic Player.State state()
public void pause()
public void resume(boolean countIn)
public void startAt(int barIndex, boolean countIn)
barIndex
- 0-based bar index to start atcountIn
- if true a count-in bar is played before the first barpublic void setBarStartHandler(Dispatcher.EventHandler handler, int delay_ms)
handler
- the bar start handler - index argument is 0-based bar index. ci is true for a count-in bardelay_ms
- the delay from the event to calling the handler. Can be negative to anticipate the eventpublic void setBeatHandler(Dispatcher.EventHandler handler, int delay_ms)
handler
- the beat handler - index argument to event is 0-based beat index. ci is true for a count-in bardelay_ms
- the delay from the event to calling the handler. Can be negative to anticipate the eventpublic void setEndHandler(Dispatcher.EventHandler handler, int delay_ms)
handler
- the end handler - called on completion of play, but not on stop or pausedelay_ms
- the delay from the event to calling the handler. Can be negative to anticipate the eventpublic void setNoteHandler(Dispatcher.NoteEventHandler handler, int delay_ms)
handler
- the note handler - called with a list of notes (chord) starting at this timedelay_ms
- the delay from the event to calling the handler. Can be negative to anticipate the event