I want its should only add a new QueueItem if the uri is not the same as the previous click
and if is the same. if it has started already plying it should resume but if it has finish playing and it is the same uri it should rewind but only with a click
so i did it like this
root.binding.playChat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
root.binding.textView40.setTag(position);
Gson gson = new GsonBuilder().create();
ChatMessageViewModel chat = getCurrentList().get(position);
String attachments = gson.toJson(chat.getAttachments());
Type collectionType = new TypeToken<Collection<Attachments>>() {}.getType();
Collection<Attachments> enums = gson.fromJson(attachments, collectionType);
for (Attachments a : enums) {
String path = a.getPath();
try {
currentPlay = root.binding.playChat;
seekBar = root.binding.sb;
textView = root.binding.textView40;
String preUrl = "";
String newURL = domain + path + "?apikey=" + encodeValue(apikey) + "&auth=" + auth + "&secret=" + encodeValue(secret);
String oldUrl = preUrl;
if (!newURL.equals(url)) {
url = newURL;
Uri myUri = Uri.parse(url);
voicemailViewModel.addURItoQueueChat(MediaControllerCompat.getMediaController(ChatActivity.this), myUri);
changePlayback();
}else {
MediaControllerCompat.TransportControls transportControls = MediaControllerCompat.getMediaController(ChatActivity.this).getTransportControls();
int pbState = MediaControllerCompat.getMediaController(ChatActivity.this).getPlaybackState().getState();
if (pbState == PlaybackStateCompat.STATE_PLAYING) {changePlayback();
}else if (pbState == PlaybackStateCompat.STATE_PAUSED ) {changePlayback();
}else {
VoicemailPlayingService.getLiveState().observe(ChatActivity.this, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
if (integer == ExoPlayer.STATE_ENDED){
MediaControllerCompat.getMediaController(ChatActivity.this).getTransportControls().seekTo(0);
MediaControllerCompat.getMediaController(ChatActivity.this).getTransportControls().pause();
currentPlay.setImageResource(R.drawable.ic_outline_play_arrow_24);}
}
});
}
}
} catch (Exception e) {}
}
}
the changePlayback() is like this
void changePlayback() {
int pbState = MediaControllerCompat.getMediaController(ChatActivity.this).getPlaybackState().getState();
if (pbState == PlaybackStateCompat.STATE_PLAYING) {
MediaControllerCompat.getMediaController(this).getTransportControls().pause();
currentPlay.setImageResource(R.drawable.ic_outline_play_arrow_24);
} else if (pbState == PlaybackStateCompat.STATE_PAUSED || pbState ==0 ){
MediaControllerCompat.getMediaController(this).getTransportControls().play();
currentPlay.setImageResource(R.drawable.ic_baseline_pause_24);}
}