I need to add a textview in MediaController which shows the name of the song playing. Currently , I am overriding setAnchorView method of MediaController class . But I dont know how should I get the song name populated there . I have the value of song name playing in the Activity class. So how should I approach ? This is my current approach. It should show song name even when pressing back and going back to the app since the music keeps playing.
MediaControllerClass;
@Override
public void setAnchorView(View view) {
String text = getSongTitle();
if (text!=null)
{
Log.d(this.getClass().getName(), text);
TextView tvSongTitle = new TextView(getContext());
tvSongTitle.setText(text);
tvSongTitle.setTextSize(40.0f);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.TOP;
addView(tvSongTitle, params);
}
super.setAnchorView(view);
}
public String getSongTitle()
{
main = new MainActivity();
return main.getSongTitle();
}
Inside Activity Class:
public String getSongTitle()
{
Log.d(this.getClass().getName(), "getsongtitle");
Intent i = getIntent();
if (i!=null)
{
String songTitle = i.getStringExtra("songName");
if(songTitle!=null)
{
Log.d(this.getClass().getName(),songTitle );
return songTitle;
}
else
{
return null;
}
}
else
{
return null;
}
}
Service Class:
Intent i = new Intent(MusicService.this,MainActivity.class);
i.putExtra("songName",songTitle);
startActivity(i);