Skip to content

Commit

Permalink
完善demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauzy committed Apr 12, 2018
1 parent 61cf8c9 commit 858bb76
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 82 deletions.
30 changes: 0 additions & 30 deletions app/src/main/assets/hktk.lrc

This file was deleted.

20 changes: 18 additions & 2 deletions app/src/main/java/com/lauzy/freedom/lyricview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

Expand All @@ -15,9 +16,8 @@
import java.io.IOException;
import java.util.List;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private long mCurrentTime;
private MediaPlayer mMediaPlayer = new MediaPlayer();
private LrcView mLrcView;
private Handler mHandler = new Handler();
Expand Down Expand Up @@ -69,6 +69,8 @@ private void init() {
mSeekBar = findViewById(R.id.seek_play);
mTvStart = findViewById(R.id.tv_start);
mTvEnd = findViewById(R.id.tv_end);
findViewById(R.id.btn_play).setOnClickListener(this);
findViewById(R.id.btn_pause).setOnClickListener(this);
mLrcView.setLrcData(lrcs);
mLrcView.setOnPlayIndicatorLineListener(new LrcView.OnPlayIndicatorLineListener() {
@Override
Expand Down Expand Up @@ -96,4 +98,18 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_play:
mMediaPlayer.start();
mLrcView.resume();
break;
case R.id.btn_pause:
mMediaPlayer.pause();
mLrcView.pause();
break;
}
}
}
Binary file added app/src/main/res/drawable/play_music.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -11,23 +12,29 @@
android:id="@+id/lrc_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
app:currentIndicateLrcColor="@color/colorAccent"
app:indicatorTextColor="@android:color/holo_orange_dark"
app:lrcHorizontalPadding="30dp"
app:playIcon="@drawable/play_music"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_start"
android:text="00:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:text="00:00"/>

<SeekBar
android:id="@+id/seek_play"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_weight="1"/>

<TextView
android:id="@+id/tv_end"
Expand Down
23 changes: 9 additions & 14 deletions library/src/main/java/com/lauzy/freedom/library/LrcHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -28,7 +25,6 @@
*/
public class LrcHelper {

private static final SimpleDateFormat FORMAT = new SimpleDateFormat("mm:ss", Locale.CHINA);
private static final String CHARSET = "utf-8";
//[03:56.00][03:18.00][02:06.00][01:07.00]原谅我这一生不羁放纵爱自由
private static final String LINE_REGEX = "((\\[\\d{2}:\\d{2}\\.\\d{2}])+)(.*)";
Expand Down Expand Up @@ -61,9 +57,6 @@ private static List<Lrc> parseInputStream(InputStream inputStream) {
br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
if (line.trim().equals("")) {
continue;
}
List<Lrc> lrcList = parseLrc(line);
if (lrcList != null && lrcList.size() != 0) {
lrcs.addAll(lrcList);
Expand Down Expand Up @@ -127,13 +120,15 @@ private static List<Lrc> parseLrc(String lrcLine) {
}

public static String formatTime(long time) {
Date date = new Date(time);
String str = "";
try {
str = FORMAT.format(date);
} catch (Exception e) {
e.printStackTrace();
int min = (int) (time / 60000);

This comment has been minimized.

Copy link
@ronaksuchak

ronaksuchak Jul 11, 2019

you who = ( you ) (time / 60000 );
replace with
int min = (int) (time / 60000);

int sec = (int) (time / 1000 % 60);
return adjustFormat(min) + ":" + adjustFormat(sec);
}

private static String adjustFormat(int time) {
if (time < 10) {
return "0" + time;
}
return str;
return time + "";
}
}
Loading

0 comments on commit 858bb76

Please sign in to comment.