public class MediaFragment
extends Fragment
Modifier and Type | Class and Description |
---|---|
private class |
MediaFragment.PrepareExerciseWorker
Prepares a WAVE file for playback of a given
Exercise |
Modifier and Type | Field and Description |
---|---|
private Exercise |
currentExercise
Current
Exercise , used for state management. |
private AssetManager |
mAssetMan |
private Context |
mCtx |
private MediaPlayer |
mPlayer |
private boolean |
mPlayerReady
Set to true if the MediaPlayer is ready to play an exercise
|
private ImageButton |
playButton
The play/pause button displayed in
ExerciseFragment . |
private boolean |
playImmediately
Set to true if requested to play media immediately after preparing it
|
private static java.lang.String |
PREFERENCES_CURRENTEXERCISEOBJECT |
private static java.lang.String |
PREPARED_WAV_FILENAME
The name of the most recently generated WAV file
|
private static int |
SAMPLE_COUNT
The amount of samples available
|
private static int |
SAMPLES_BITRATE
the bit rate of the samples we use to generate our exercises
|
private static int |
SAMPLES_RATE
The sampling rate of the samples we use to generate our exercises
|
Constructor and Description |
---|
MediaFragment() |
Modifier and Type | Method and Description |
---|---|
void |
clickPlay()
Called when the Play button is clicked, if the MediaPlayer is ready for playback, start playback,
if it is playing, pause playback, do nothing otherwise.
|
private byte[] |
createWavHeader(int bufSize,
int samplerate,
int bitrate)
Returns a WAV header for the given parameters
|
void |
onCreate(Bundle savedInstanceState)
Set up MediaPlayer, Assets and a few listeners
|
View |
onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) |
void |
onDestroy()
TODO: Should release MediaPlayer in onPause().
|
void |
onPause()
In order to conform with FN-A1 to 4, we must pause playback when the user leaves the activity
|
void |
onSaveInstanceState(Bundle outState) |
void |
prepareExercise(Exercise exercise)
Prepare and load a WAV file for the given Exercise.
|
private byte[] |
prepareExerciseUnit(java.util.List<java.lang.Integer> exerciseUnit)
Mixes the samples associated with the given List of Integers
|
void |
requestPlayback()
Make a request to start playing media as soon as it is available, used when the App wants
a single UI event to prepare an exercise and then play it.
|
private void |
setButtonImagePause()
Set the Play button to display a Pause icon
|
private void |
setButtonImagePlay()
Set the Play button to display a Play icon
|
void |
setEmpty() |
private static final java.lang.String PREPARED_WAV_FILENAME
private static final java.lang.String PREFERENCES_CURRENTEXERCISEOBJECT
private Context mCtx
private AssetManager mAssetMan
private MediaPlayer mPlayer
private boolean mPlayerReady
private ImageButton playButton
ExerciseFragment
.private static final int SAMPLES_BITRATE
private static final int SAMPLES_RATE
private static final int SAMPLE_COUNT
private boolean playImmediately
public void onCreate(Bundle savedInstanceState)
savedInstanceState
- the saved instance state.public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
public void onSaveInstanceState(Bundle outState)
public void onDestroy()
public void onPause()
public void clickPlay()
private void setButtonImagePlay()
private void setButtonImagePause()
public void setEmpty()
public void prepareExercise(Exercise exercise)
exercise
- The Exercise for which to prepare the MediaFragmentpublic void requestPlayback()
private byte[] prepareExerciseUnit(java.util.List<java.lang.Integer> exerciseUnit) throws java.io.IOException
Loads all the samples associated with the given List
exerciseUnit
- The list of samples to mixjava.io.IOException
private byte[] createWavHeader(int bufSize, int samplerate, int bitrate)
bufSize
- The size of the output WAV (header + data) in bytessamplerate
- The sample rate of the WAV filebitrate
- The bitrate of the WAV file