I'm trying to implement play/pause button in notification via frame layout but when I click to pause the mediaPlayer it doesn't updates to show the play button in the notification.How to update the view?
RemoteViews nv = new RemoteViews(getPackageName(), R.layout.notificationLayout);
Intent switchIntent = new Intent("com.example.android.ACTION_PLAY");
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 100, switchIntent, 0);
nv.setOnClickPendingIntent(R.id.pause, pendingSwitchIntent);
In Broadcast Receiver class
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equalsIgnoreCase("com.example.app.ACTION_PLAY")){
if(mp.isPlaying())
{
nv.setViewVisibility(R.id.pause, View.INVISIBLE);
nv.setViewVisibility(R.id.play, View.VISIBLE);
mp.pause();
}
else
{
nv.setViewVisibility(R.id.play, View.INVISIBLE);
nv.setViewVisibility(R.id.pause, View.VISIBLE);
mp.start();
}
}
}