BaseAdapter's method, getView() method will provide you with the view and you should change the color of your of current track by setting a variable in your list and reset that color to default when the variable is not set.
if (is this the current playing track) {
// Set the color of the view.
} else {
// Set the color to default.
}
If you have implemented this logic currently, then whenever you change the current track and also the variable in your list that tracks the current playing Media, a simple songAdt.notifyDataSetChanged() will ask the BaseAdapter to be called again and will set the view as per the new data. For More indepth understanding of ListView you can refer this talk. It will help.
Preferably consider training yourself with RecyclerView, its the present. ListView was a dreadful past.
public class Activity implements SongChangedListener {
...
@Override
onCreate() {
....
PlayerManager pManager = new PlayerManager();
}
onResume() {
pManager.setListener(this);
}
onPause() {
pManager.setListener(null);
}
@Override
void songChanged (MediaId idOfSong) {
if (getActivity == null) //If you received a callback after activity was killed.
return;
// Change the current song as not playing in List. (for your adapter)
// Change the idOfSong to currently playing in List (for your adapter).
// change currentSong = idOfSong;
// notify that the data in List has changed (songAdt.notifyDataSetChanged)
}
}
And in Your PlayerManager, you can create the interface, or maybe a seperate class for the interface, doesn't matter how you send the interface instance.
public class PlayerManager {
...
private SongChangedListener mListener;
...
public PlayerManager() {
}
public void setListener(SongChangedListener listener) {
mListener = listener;
}
public interface SongChangedListener {
void songChanged(MediaId idOfSong);
}
...
public void playSong() {
...
if (mListener != null)
mListener.songChanged(idOfNextSong);
...
}
In your answer you are passing an activity into your service, which feels wrong in many ways. If you want to implement communication between activity and service, there are many other ways to do this. Usually I use a Messenger in conjunction with a Handler. I would provide more details but it would be more beneficial if you explore it in documentation and in other answers. It is easy to implement once you understand how Messengers work.
Also, if you are looking for a fullfledged MediaPlayer Application, your implementation will require a lot more boiler code. Also you will have to handle MediaButton clicks(if someone clicked on play/pause on their bluetooth headphones or on their watch). Preferably MediaSessionCompat is a better implementation. You can also refer the following open Source MediaPlayer, which implements all the minimum required functionalities pretty nicely android-UniversalMusicPlayer.