I'm trying to implement a karaoke like class. When the user clicks on any item from the list it opens an audio player with the lyrics displayed that should scroll according to the audio position.
All my audios are in the raw folders. I use parcelable in my model class to send the text onclick according to position.
Any help will be much appreciated thanks.
Here's my code :
Model class:
public class readhelper implements Parcelable {
int image,audie;
String title,title2,lyric;
public readhelper(int image, String title, String title2,int audie, String
lyric) {
this.image=image;
this.title=title;
this.title2=title2;
this.audie=audie;
this.lyric=lyric;
}
I get the strings like this in oncreate of my player activity
intent=getIntent();
readhelper ww=intent.getParcelableExtra("readlist");
String tt= ww.getTitle();
String ds= ww.getLyric();
TextView txt=findViewById(R.id.audiottle);
TextView dsc=findViewById(R.id.lyrics);
txt.setText(tt);
dsc.setText(ds);
dsc.setMovementMethod(new ScrollingMovementMethod())<
Audio play thread and on click method. It's here I don't know how to get the strings so it can't scroll at the same time the audio is playing and highlight the current line being read. Just like a music player displaying lyrics.
private View.OnClickListener pausePlay= new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!playPause){
play.setImageResource(R.drawable.ic_pause);
if(init)
startNewSong();
else {
if(!Player.isPlaying())
Player.start();
}
playPause=true;
}else {
play.setImageResource(R.drawable.ic_play);
if(Player.isPlaying())
Player.pause();
playPause=false;
}
}
};
public void startNewSong()
if(Player!=null){
Player.stop();
Player.release();
readhelper ww = intent.getParcelableExtra("readlist");
int audio = ww.getAudie();
Player= MediaPlayer.create(getApplicationContext(),audio);
Player.start();
init=false;
Player.setOnCompletionListener(this);
}else {
readhelper ww = intent.getParcelableExtra("readlist");
int audio = ww.getAudie();
Player = MediaPlayer.create(getApplicationContext(), audio)
Player.start();
play.setImageResource(R.drawable.ic_pause);
seekBar.setMax(Player.getDuration()/ 1000);
init=false;
Player.setOnCompletionListener(this);
}
}
I'm a newbie so please provide some explanations with code. Thank you for taking the time and reading.
What I have tried:
I tried using the code here [https://github.com/starrydeveloper/karaokely] as a guide. But I get stuck when I have to setText for each lyrics that's obviously parceled as one. So I can't individually scroll them. I tried using Lyricview library too.