private void playTone() {
// 上班时间到了,响铃并显示“可以下班啦!”
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mRingtone = RingtoneManager.getRingtone(MainActivity.this, uri);
mRingtone.play();
}
// 播放res/raw文件夹下的音频
private void playTone() {
Uri uri = Uri.parse("android.resource://com.vzone.musicdemo/" + R.raw.hong);
mRingtone = RingtoneManager.getRingtone(MainActivity.this, uri);
// 设置静音模式也播放声音
mRingtone.setStreamType(AudioManager.STREAM_ALARM);
mRingtone.play();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
unregisterReceiver(mTimeReceiver);
if (mRingtone != null && mRingtone.isPlaying()) {
mRingtone.stop();
}
}
播放一段音乐
最新推荐文章于 2021-06-02 22:48:05 发布