如何設置從R.raw聲音RingtoneManager設定音響RingtoneManager ....如何從R.raw
我想設置我的聲音,但我不知道將其設置
Uri defaultRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(context, defaultRingtoneUri);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp)
{
mp.release();
}
});
mediaPlayer.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
感謝您的幫助!和對不起我的英文不好
試試這個https://stackoverflow.com/questions/7499605/how-to-play-the-audio-files-directly-from-res-raw-folder – Raghavendra