私はuseeventsで簡単な解決策を見つけました-それはあなたの問題を解決するので答えを確認してください:)
mediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
mediaPlayer.stop();
}
});
http://developer.android.com/reference/android/media/MediaPlayer.html
release()について覚えておいてください。
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.release();
}
});
使用したい完全なコードは、着信音を好きなものに設定する必要があります。
AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
int volume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
Uri notificationSoundUri = Uri.parse(prefs.getString("notification_sound", "DEFAULT_SOUND"));
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(view.getContext(), notificationSoundUri);
} catch (Exception e1) {
e1.printStackTrace();
mediaPlayer.release();
return;
}
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.release();
}
});
try {
mediaPlayer.prepare();
} catch (Exception e1) {
e1.printStackTrace();
mediaPlayer.release();
return;
}
mediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
// TODO Auto-generated method stub
mediaPlayer.stop();
mediaPlayer.start();
}
});
mediaPlayer.setVolume(volume, volume);
mediaPlayer.start();