I have implemented music player which fires a custom notification when stream audio is playing.
Everything is working and I can play/pause the audio using the button
This should work. Just make your notification and notificationManager a static global variable.
public class RemoteControlReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(action.equalsIgnoreCase("com.example.test.ACTION_PLAY")){
if(mediaplayer.isPlaying()){
mediaplayer.pause();
notificationView.setImageViewResource(R.id.button1, R.drawable.play);
notification.contentView = notificationView;
notificationManager.notify(1, notification);
}
else {
mediaplayer.start();
notificationView.setImageViewResource(R.id.button1, R.drawable.pause);
notification.contentView = notificationView;
notificationManager.notify(1, notification);
}
}
}
}