Play audio alert if child is disconnected
If the child device disconnects unexpectedly, alert the user, in case they were not expecting the disconnect. The audio file being played is originally from here: https://freesound.org/people/pan14/sounds/263655/
This commit is contained in:
@@ -28,6 +28,7 @@ import android.app.Activity;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioTrack;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
@@ -141,6 +142,11 @@ public class ListenActivity extends Activity
|
||||
|
||||
if(Thread.currentThread().isInterrupted() == false)
|
||||
{
|
||||
// If this thread has not been interrupted, likely something
|
||||
// bad happened with the connection to the child device. Play
|
||||
// an alert to notify the user that the connection has been
|
||||
// interrupted.
|
||||
playAlert();
|
||||
|
||||
ListenActivity.this.runOnUiThread(new Runnable()
|
||||
{
|
||||
@@ -169,4 +175,26 @@ public class ListenActivity extends Activity
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void playAlert()
|
||||
{
|
||||
final MediaPlayer mp = MediaPlayer.create(this, R.raw.upward_beep_chromatic_fifths);
|
||||
if(mp != null)
|
||||
{
|
||||
Log.i(TAG, "Playing alert");
|
||||
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
|
||||
{
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp)
|
||||
{
|
||||
mp.release();
|
||||
}
|
||||
});
|
||||
mp.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e(TAG, "Failed to play alert");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user