我已经在背景中启动了音乐播放器..当生成通知时.. 我想在用户点击通知或向左或向右滑动用户关闭通知时停止音乐播放器
这里是我的代码生成通知和播放音乐文件
private static void generateNotification(Context context, String message) {
int icon = R.drawable.islamicicon;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, PrayTimtableFragment.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
String check[]=message.split(" ");
if(check[0].equals("Please"))
{
SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
int iTmp = sp.load(context, R.raw.azan1, 1); // in 2nd param u have to pass your desire ringtone
sp.play(iTmp, 1, 1, 0, 0, 1);
mPlayer = MediaPlayer.create(context, R.raw.azan1); // in 2nd param u have to pass your desire ringtone
//mPlayer.prepare();
mPlayer.start();
}
else
{
notification.defaults |= Notification.DEFAULT_SOUND;
}
// notification.sound = Uri.parse("android.resource://" + context.getPackageName() +R.raw.azan1);
// Vibrate if vibrate is enabled
//notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
我想在点击通知或关闭
时停止播放音乐提前致谢