Formatted MultiPlayer.java
This commit is contained in:
parent
78c765fcac
commit
3d6bf809f8
1 changed files with 36 additions and 15 deletions
|
@ -31,7 +31,9 @@ import code.name.monkey.retromusic.R;
|
||||||
import code.name.monkey.retromusic.service.playback.Playback;
|
import code.name.monkey.retromusic.service.playback.Playback;
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||||
|
|
||||||
/** @author Andrew Neal, Karim Abou Zeid (kabouzeid) */
|
/**
|
||||||
|
* @author Andrew Neal, Karim Abou Zeid (kabouzeid)
|
||||||
|
*/
|
||||||
public class MultiPlayer
|
public class MultiPlayer
|
||||||
implements Playback, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener {
|
implements Playback, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener {
|
||||||
public static final String TAG = MultiPlayer.class.getSimpleName();
|
public static final String TAG = MultiPlayer.class.getSimpleName();
|
||||||
|
@ -45,7 +47,9 @@ public class MultiPlayer
|
||||||
|
|
||||||
private boolean mIsInitialized = false;
|
private boolean mIsInitialized = false;
|
||||||
|
|
||||||
/** Constructor of <code>MultiPlayer</code> */
|
/**
|
||||||
|
* Constructor of <code>MultiPlayer</code>
|
||||||
|
*/
|
||||||
MultiPlayer(final Context context) {
|
MultiPlayer(final Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
mCurrentMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
mCurrentMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
||||||
|
@ -155,13 +159,17 @@ public class MultiPlayer
|
||||||
this.callbacks = callbacks;
|
this.callbacks = callbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return True if the player is ready to go, false otherwise */
|
/**
|
||||||
|
* @return True if the player is ready to go, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return mIsInitialized;
|
return mIsInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Starts or resumes playback. */
|
/**
|
||||||
|
* Starts or resumes playback.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
try {
|
try {
|
||||||
|
@ -172,14 +180,18 @@ public class MultiPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resets the MediaPlayer to its uninitialized state. */
|
/**
|
||||||
|
* Resets the MediaPlayer to its uninitialized state.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
mCurrentMediaPlayer.reset();
|
mCurrentMediaPlayer.reset();
|
||||||
mIsInitialized = false;
|
mIsInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Releases resources associated with this MediaPlayer object. */
|
/**
|
||||||
|
* Releases resources associated with this MediaPlayer object.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
stop();
|
stop();
|
||||||
|
@ -189,7 +201,9 @@ public class MultiPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Pauses playback. Call start() to resume. */
|
/**
|
||||||
|
* Pauses playback. Call start() to resume.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean pause() {
|
public boolean pause() {
|
||||||
try {
|
try {
|
||||||
|
@ -200,7 +214,9 @@ public class MultiPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks whether the MultiPlayer is playing. */
|
/**
|
||||||
|
* Checks whether the MultiPlayer is playing.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
return mIsInitialized && mCurrentMediaPlayer.isPlaying();
|
return mIsInitialized && mCurrentMediaPlayer.isPlaying();
|
||||||
|
@ -291,7 +307,9 @@ public class MultiPlayer
|
||||||
return mCurrentMediaPlayer.getAudioSessionId();
|
return mCurrentMediaPlayer.getAudioSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onError(final MediaPlayer mp, final int what, final int extra) {
|
public boolean onError(final MediaPlayer mp, final int what, final int extra) {
|
||||||
mIsInitialized = false;
|
mIsInitialized = false;
|
||||||
|
@ -308,7 +326,9 @@ public class MultiPlayer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCompletion(final MediaPlayer mp) {
|
public void onCompletion(final MediaPlayer mp) {
|
||||||
if (mp.equals(mCurrentMediaPlayer) && mNextMediaPlayer != null) {
|
if (mp.equals(mCurrentMediaPlayer) && mNextMediaPlayer != null) {
|
||||||
|
@ -324,5 +344,6 @@ public class MultiPlayer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCrossFadeDuration(int duration) { }
|
public void setCrossFadeDuration(int duration) {
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue