0

I have started music player In background ..When Notification is generated .. I want to stop music player when User Click On Notification Or User Close Notification on Slide left or right

here Is My Code where generating Notification And playing a music file

 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); 



    }

I want to stop music player when click on notification or close

Thanks In Advance

user3825086
  • 111
  • 1
  • 2
  • 12

0 Answers0