Subhomoy Goswami
Lurker
Hello every body, i'm new to android and i'm creating a mp3 app where there will be a list of all the mp3s and two buttons. "play" and "download" button.
The problem i'm facing is that when ever i'm clicking on any of the play button, the music starts and the button changes from play to pause.
but when i'm clicking on any other list, the same happens but the previous play button should change to "play" button which I cant make it work.
Below i'm sharing my code.
Any help will be appreciated. Thank you in advance..
The problem i'm facing is that when ever i'm clicking on any of the play button, the music starts and the button changes from play to pause.
but when i'm clicking on any other list, the same happens but the previous play button should change to "play" button which I cant make it work.
Below i'm sharing my code.
Code:
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.songs_list,null,true);
}
final Songs songs = getItem(position);
TextView songs_name = (TextView) convertView.findViewById(R.id.songs_name);
songs_name.setText(songs.getName());
final ImageButton listPlayBtn = (ImageButton) convertView.findViewById(R.id.listPlayBtn);
final Integer play = 0;
listPlayBtn.setOnClickListener(new View.OnClickListener() {
String song_name = songs.getName();
String song_url = songs.getUrl();
Integer play1 = play;
@Override
public void onClick(View v) {
MucisPlayer mp = new MucisPlayer();
if(play1 == 0) {
mp.play1(song_url, song_name, mediaplayer);
play1 = 1;
System.out.println("Play");
listPlayBtn.setImageResource(R.drawable.pause);
}
else
{
mp.pause(mediaplayer);
play1 = 0;
System.out.println("Pause");
listPlayBtn.setImageResource(R.drawable.play);
}
}
});
final ImageButton listDownloadBtn = (ImageButton) convertView.findViewById(R.id.listDownloadBtn);
listDownloadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String song_name = songs.getName();
String song_url = songs.getUrl();
System.out.println("Download Clicked");
Album_details ad = new Album_details();
ad.downloadFileFromNet(song_url,song_name);
}
});
return convertView;
}
Any help will be appreciated. Thank you in advance..