1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| try {
//
//
//
private MediaPlayer mMediaPlayer;
//
//
//
String alarme = tinydb.getString("alarme");
File ContactsFolderDir = new File(Environment.getExternalStorageDirectory() + File.separator + "Mesalarmes");
String myFile = ContactsFolderDir + File.separator + alarme + ".mp3";
mMediaPlayer.setDataSource(myFile);
mMediaPlayer.prepare();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), "ErreurFichier:" + ex, Toast.LENGTH_LONG).show();
}
try {
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
if (mAudioFocusHelper != null) {
mAudioFocusHelper.requestFocus();
}
Toast.makeText(getApplicationContext(), "BeforePlay:" + myFile, Toast.LENGTH_LONG).show();
mMediaPlayer.start();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), "ErreurPlay:" + ex, Toast.LENGTH_LONG).show();
} |
Partager