Created
August 7, 2020 12:52
-
-
Save bengongon97/beaccb52c0d2b86ade5eb99fe16726e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void updateSeekBar(final long currentPosition, long duration){ | |
//seekbar | |
binding.musicSeekBar.setMax((int) (duration / 1000)); | |
if(mHwAudioPlayerManager != null){ | |
int mCurrentPosition = (int) (currentPosition / 1000); | |
binding.musicSeekBar.setProgress(mCurrentPosition); | |
setProgressText(mCurrentPosition); | |
} | |
binding.musicSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |
@Override | |
public void onStopTrackingTouch(SeekBar seekBar) { | |
//Log.i("ONSTOPTRACK", "STOP TRACK TRIGGERED."); | |
} | |
@Override | |
public void onStartTrackingTouch(SeekBar seekBar) { | |
//Log.i("ONSTARTTRACK", "START TRACK TRIGGERED."); | |
} | |
@Override | |
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |
if(mHwAudioPlayerManager != null && fromUser){ | |
mHwAudioPlayerManager.seekTo(progress*1000); | |
} | |
if(!isReallyPlaying){ | |
setProgressText(progress); //when the song is not playing and user updates the seekbar, seekbar still should be updated | |
} | |
} | |
}); | |
} | |
public void setProgressText(int progress){ | |
String progressText = String.format(Locale.US, "%02d:%02d", | |
TimeUnit.MILLISECONDS.toMinutes(progress*1000), | |
TimeUnit.MILLISECONDS.toSeconds(progress*1000) - | |
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(progress*1000)) | |
); | |
binding.progressTextView.setText(progressText); | |
} | |
public void setSongDetails(HwAudioPlayItem currentItem){ | |
if(currentItem != null){ | |
getBitmapOfCover(currentItem); | |
if(!currentItem.getAudioTitle().equals("")) | |
binding.songNameTextView.setText(currentItem.getAudioTitle()); | |
else{ | |
binding.songNameTextView.setText("Try choosing a song"); | |
} | |
if(!currentItem.getSinger().equals("")) | |
binding.artistNameTextView.setText(currentItem.getSinger()); | |
else | |
binding.artistNameTextView.setText("From the playlist"); | |
binding.albumNameTextView.setText("Album Unknown"); //there is no field assinged to this in HwAudioPlayItem | |
binding.progressTextView.setText("00:00"); //initial progress of every song | |
long durationTotal = currentItem.getDuration(); | |
String totalDurationText = String.format(Locale.US, "%02d:%02d", | |
TimeUnit.MILLISECONDS.toMinutes(durationTotal), | |
TimeUnit.MILLISECONDS.toSeconds(durationTotal) - | |
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(durationTotal)) | |
); | |
binding.totalDurationTextView.setText(totalDurationText); | |
} | |
else{ | |
//Here is measure to prevent the bad first opening of the app. After user | |
//selects a song from the playlist, here should never be executed again. | |
binding.songNameTextView.setText("Try choosing a song"); | |
binding.artistNameTextView.setText("From the playlist"); | |
binding.albumNameTextView.setText("It is at right-top of the screen"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment