Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
      }
//rest of code


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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900