|
1 |
| -zhengken's first open source software |
| 1 | +# LyricView |
| 2 | +LyricView is a powerful and flexible custom view to display lyrics within music player under Android |
| 3 | +## Screenshot |
| 4 | + |
| 5 | +[LyricViewDemo.apk][1] |
| 6 | +## Usage |
| 7 | +### Gradle dependency |
| 8 | +### XML code |
| 9 | + //step 1 |
| 10 | + <me.zhengken.lyricview.LyricView |
| 11 | + android:id="@+id/custom_lyric_view" |
| 12 | + android:layout_width="match_parent" |
| 13 | + android:layout_height="match_parent" /> |
| 14 | +### Java code |
| 15 | + //step 2 |
| 16 | + LyricView mLyricView = (LyricView)findViewById(R.id.custom_lyric_view); |
| 17 | + |
| 18 | + //step 3 |
| 19 | + mLyricView.setLyricFile(lyricFile); |
| 20 | + |
| 21 | + //step 4, update LyricView every interval |
| 22 | + mLyricView.setCurrentTimeMillis(progress); |
| 23 | + |
| 24 | + //step 5, implement the interface when user drag lyrics and click the play icon |
| 25 | + mLyricView.setOnPlayerClickListener(new LyricView.OnPlayerClickListener() { |
| 26 | + @Override |
| 27 | + public void onPlayerClicked(long progress, String content) { |
| 28 | + |
| 29 | + } |
| 30 | + }); |
| 31 | +### XML attributes |
| 32 | +|Attributes|Format|Default|Description| |
| 33 | +|:--|:--|:--|:--| |
| 34 | +|fadeInFadeOut|boolean|false|Enable lyrics fadeInFadeOut or not| |
| 35 | +|hint|string|No Lyrics|Display when not exist lyric file| |
| 36 | +|hintColor|color|`#FFFFFF`|The color of hint text| |
| 37 | +|textSize|dimension|16sp|The text size of lyrics| |
| 38 | +|textColor|color|`#8D8D8D`|The color of lyrics| |
| 39 | +|highlightColor|color|`#FFFFFF`|The color of current lyric that playing| |
| 40 | +|textAlign|enum|CENTER|The alignment of lyrics| |
| 41 | +|maxLength|dimension|300dp|Line feed when lyric'width beyond maxLength| |
| 42 | +|lineSpace|dimension|25dp|Line space| |
| 43 | +### Java API |
| 44 | +|Methods|Description| |
| 45 | +|:--|:--| |
| 46 | +|`setOnPlayerClickListener(OnPlayerClickListener listener)`|Callback when click the play icon| |
| 47 | +|`setAlignment(@Alignment int alignment)`|Set the alignment of the lyrics| |
| 48 | +|`setCurrentTimeMillis(long current)`|Scroll lyrics to the specify TimeMillis| |
| 49 | +|`setLyricFile(File file)`|Set the lyric file, and auto set the charset by `juniversalchardet-1.0.3`| |
| 50 | +|`setLyricFile(File file, String charset)`|Set the lyric file with the specified charset| |
| 51 | +|`setTypeface(Typeface typeface)`|Set the typeface of lyrics| |
| 52 | +|`reset()`|Reset the LyricView| |
| 53 | +## License |
2 | 54 |
|
3 |
| - |
| 55 | + |
| 56 | + [1]: https://github.com/zhengken/LyricViewDemo/tree/master/sample |
0 commit comments