I am displaying notification for music player inside service class with buttons and textview. The text is getting updated whenever song changes but I need to change the ImageViewResource on click of play button it should change to pause once music stopped. Another issue what I am facing is when the textview text changes the whole notification view refreshes for 1 sec and then only text changes. How could I stop the refresh of whole view?This is the code I tried so far:
Service class:
@Override
public int onStartCommand(Intent intent,int flags,int startId)
{
if(intent!=null)
{
String action = intent.getAction();
if(!TextUtils.isEmpty(action))
{
if(action.equals(ACTION_PAUSE))
{
remoteView.setImageViewResource(R.id.btnPlay_notif,R.drawable.btn_pause); //changing imageview frm play to pause
AppWidgetManager manager = AppWidgetManager.getInstance(getApplicationContext());
manager.updateAppWidget(R.id.btnPlay_notif, remoteView); // is the app widget id given correct?
pausePlayer();
}}
return 1;
}
@Override
public void onPrepared(MediaPlayer mp) {
mp.start;
Context context = getApplicationContext();
remoteView = new RemoteViews(context.getPackageName(),
R.layout.notification);
remoteView.setTextViewText(R.id.tv_song_title_notif, songTitle);
}