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:
@@ -36,3 +36,5 @@ proposed changed.
|
|||||||
|
|
||||||
App icon originals from [WPZOOM](http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons)
|
App icon originals from [WPZOOM](http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons)
|
||||||
and formatted using [Android Asset Studio](https://romannurik.github.io/AndroidAssetStudio/index.html).
|
and formatted using [Android Asset Studio](https://romannurik.github.io/AndroidAssetStudio/index.html).
|
||||||
|
|
||||||
|
Audio file originals from [freesound](https://freesound.org).
|
||||||
|
|||||||
BIN
res/raw/upward_beep_chromatic_fifths.ogg
Normal file
BIN
res/raw/upward_beep_chromatic_fifths.ogg
Normal file
Binary file not shown.
@@ -28,6 +28,7 @@ import android.app.Activity;
|
|||||||
import android.media.AudioFormat;
|
import android.media.AudioFormat;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.AudioTrack;
|
import android.media.AudioTrack;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -141,6 +142,11 @@ public class ListenActivity extends Activity
|
|||||||
|
|
||||||
if(Thread.currentThread().isInterrupted() == false)
|
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()
|
ListenActivity.this.runOnUiThread(new Runnable()
|
||||||
{
|
{
|
||||||
@@ -169,4 +175,26 @@ public class ListenActivity extends Activity
|
|||||||
|
|
||||||
super.onDestroy();
|
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