To display lyrics, add the me.zhengken.lyricview.LyricView component to your XML layout and control it via Java code.
1. XML Layout
Add the view to your layout file:
<me.zhengken.lyricview.LyricView
android:id="@+id/custom_lyric_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
2. Java Implementation
Initialize the view, load a lyric file, and update the progress periodically:
LyricView mLyricView = (LyricView)findViewById(R.id.custom_lyric_view);
// Set the lyric file
mLyricView.setLyricFile(lyricFile);
// Update the view every interval (e.g., from your music player progress)
mLyricView.setCurrentTimeMillis(progress);
// Handle user interaction (dragging lyrics or clicking play icon)
mLyricView.setOnPlayerClickListener(new LyricView.OnPlayerClickListener() {
@Override
public void onPlayerClicked(long progress, String content) {
// Handle the click event with the new progress and content
}
});
LyricView mLyricView = (LyricView)findViewById(R.id.custom_lyric_view);
// step 3
mLyricView.setLyricFile(lyricFile);
// step 4, update LyricView every interval
mLyricView.setCurrentTimeMillis(progress);
// step 5, implement the interface when user drag lyrics and click the play icon
mLyricView.setOnPlayerClickListener(new LyricView.OnPlayerClickListener() {
@Override
public void onPlayerClicked(long progress, String content) {
}
});