NotificationPlayer supports MediaPlayer errors
If an error is reported while trying to play a notification,
behave as if the playback had completed.
Bug 21093153
Change-Id: Iedc7691d0b8f4d68ad75cb04292a5d7d9350552f
(cherry picked from commit a25f6fcfed)
This commit is contained in:
@@ -21,6 +21,7 @@ import android.media.AudioAttributes;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.MediaPlayer.OnCompletionListener;
|
import android.media.MediaPlayer.OnCompletionListener;
|
||||||
|
import android.media.MediaPlayer.OnErrorListener;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
@@ -36,7 +37,7 @@ import java.util.LinkedList;
|
|||||||
* - whenever audio is played, audio focus is requested,
|
* - whenever audio is played, audio focus is requested,
|
||||||
* - whenever audio playback is stopped or the playback completed, audio focus is abandoned.
|
* - whenever audio playback is stopped or the playback completed, audio focus is abandoned.
|
||||||
*/
|
*/
|
||||||
public class NotificationPlayer implements OnCompletionListener {
|
public class NotificationPlayer implements OnCompletionListener, OnErrorListener {
|
||||||
private static final int PLAY = 1;
|
private static final int PLAY = 1;
|
||||||
private static final int STOP = 2;
|
private static final int STOP = 2;
|
||||||
private static final boolean mDebug = false;
|
private static final boolean mDebug = false;
|
||||||
@@ -112,6 +113,7 @@ public class NotificationPlayer implements OnCompletionListener {
|
|||||||
// done playing. This class should be modified to use a single thread, on which
|
// done playing. This class should be modified to use a single thread, on which
|
||||||
// command are issued, and on which it receives the completion callbacks.
|
// command are issued, and on which it receives the completion callbacks.
|
||||||
player.setOnCompletionListener(NotificationPlayer.this);
|
player.setOnCompletionListener(NotificationPlayer.this);
|
||||||
|
player.setOnErrorListener(NotificationPlayer.this);
|
||||||
player.start();
|
player.start();
|
||||||
if (mPlayer != null) {
|
if (mPlayer != null) {
|
||||||
mPlayer.release();
|
mPlayer.release();
|
||||||
@@ -245,6 +247,13 @@ public class NotificationPlayer implements OnCompletionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||||
|
Log.e(mTag, "error " + what + " (extra=" + extra + ") playing notification");
|
||||||
|
// error happened, handle it just like a completion
|
||||||
|
onCompletion(mp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private String mTag;
|
private String mTag;
|
||||||
private CmdThread mThread;
|
private CmdThread mThread;
|
||||||
private CreationAndCompletionThread mCompletionThread;
|
private CreationAndCompletionThread mCompletionThread;
|
||||||
|
|||||||
Reference in New Issue
Block a user