修复了歌词BUG,优化了播放器随机播放模式
This commit is contained in:
parent
907b52a700
commit
4a502e46f7
|
@ -163,7 +163,8 @@ public class bfq extends AppCompatActivity {
|
|||
setname(bfqkz.xm.name);
|
||||
setzz(bfqkz.xm.zz);
|
||||
bfq_an.islike();
|
||||
bfqkz.mt.setTX();
|
||||
Media.setImageBitmap();
|
||||
// bfqkz.mt.setTX();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package com.muqingbfq;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.muqingbfq.api.url;
|
||||
import com.muqingbfq.fragment.Media;
|
||||
import com.muqingbfq.fragment.gd;
|
||||
import com.muqingbfq.mq.gj;
|
||||
import com.muqingbfq.mq.wj;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -60,43 +58,60 @@ public class bfq_an {
|
|||
}
|
||||
|
||||
public static class control implements View.OnClickListener {
|
||||
ImageView imageView;
|
||||
|
||||
public control(ImageView imageView) {
|
||||
this.imageView = imageView;
|
||||
setImage(-1);
|
||||
}
|
||||
|
||||
private void setImage(int i) {
|
||||
gj.sc(bfqkz.ms);
|
||||
|
||||
bfqkz.mt.setLooping(bfqkz.ms == 0);
|
||||
switch (bfqkz.ms) {
|
||||
case 0:
|
||||
imageView.setImageResource(R.drawable.mt_xh);
|
||||
if (i == -1) {
|
||||
break;
|
||||
}
|
||||
if (!bfqkz.list_baocun.isEmpty()) {
|
||||
bfqkz.list.clear();
|
||||
bfqkz.list.addAll(bfqkz.list_baocun);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
imageView.setImageResource(R.drawable.mt_sx);
|
||||
if (i == -1) {
|
||||
break;
|
||||
}
|
||||
if (!bfqkz.list_baocun.isEmpty()) {
|
||||
bfqkz.list.clear();
|
||||
bfqkz.list.addAll(bfqkz.list_baocun);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
imageView.setImageResource(R.drawable.mt_sj);
|
||||
if (i == -1) {
|
||||
break;
|
||||
}
|
||||
bfqkz.list_baocun.clear();
|
||||
bfqkz.list_baocun.addAll(bfqkz.list);
|
||||
Collections.shuffle(bfqkz.list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ImageView imageView = (ImageView) v;
|
||||
switch (bfqkz.ms) {
|
||||
case 0:
|
||||
bfqkz.ms = 1;
|
||||
imageView.setImageResource(R.drawable.mt_sx);
|
||||
// 顺序
|
||||
break;
|
||||
case 1:
|
||||
bfqkz.ms = 2;
|
||||
imageView.setImageResource(R.drawable.mt_sj);
|
||||
// 随机
|
||||
break;
|
||||
case 2:
|
||||
if (bfqkz.ms == 2) {
|
||||
bfqkz.ms = 0;
|
||||
imageView.setImageResource(R.drawable.mt_xh);
|
||||
// 循环
|
||||
break;
|
||||
} else {
|
||||
bfqkz.ms++;
|
||||
}
|
||||
setImage(bfqkz.ms);
|
||||
main.edit.putInt("ms", bfqkz.ms);
|
||||
main.edit.commit();
|
||||
// imageView.setImageDrawable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ import java.util.Random;
|
|||
public class bfqkz extends MediaBrowserServiceCompat {
|
||||
public static MediaPlayer mt = new MediaPlayer();
|
||||
public static List<MP3> list = new ArrayList<>();
|
||||
|
||||
//保存原始list顺序
|
||||
public static List<MP3> list_baocun = new ArrayList<>();
|
||||
public static List<MP3> lishi_list = new ArrayList<>();
|
||||
public static int ms;
|
||||
// 0 循环 1 顺序 2 随机
|
||||
|
@ -39,15 +42,10 @@ public class bfqkz extends MediaBrowserServiceCompat {
|
|||
public static com.muqingbfq.mq.NotificationManagerCompat notify;
|
||||
|
||||
public static int getmti(int s) {
|
||||
int i = bfqkz.list.indexOf(xm);
|
||||
if (s == 1) {
|
||||
i = bfqkz.list.indexOf(xm) + 1;
|
||||
int i = bfqkz.list.indexOf(xm) + 1;
|
||||
if (i >= bfqkz.list.size()) {
|
||||
i = 0;
|
||||
}
|
||||
} else if (s == 2) {
|
||||
i = new Random().nextInt(bfqkz.list.size());
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,13 +64,14 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
|
|||
|
||||
public static class SETUP {
|
||||
//0是关闭 1是打开 2是锁定
|
||||
public int i;
|
||||
public float TOP, Alpha;
|
||||
public String Color;
|
||||
public int Y;
|
||||
public int i = 1;
|
||||
public float Alpha = 0.9f;
|
||||
public String Color = "#0088FF";
|
||||
public int Y = -main.g;
|
||||
}
|
||||
|
||||
public SETUP setup = new SETUP();
|
||||
|
||||
public int lock() {
|
||||
if (setup != null && setup.i == 2) {
|
||||
return WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
|
||||
|
@ -79,6 +80,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
|
|||
return WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
||||
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -91,16 +93,6 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
|
|||
Type type = new TypeToken<SETUP>() {
|
||||
}.getType();
|
||||
setup = gson.fromJson(dqwb, type);
|
||||
} else {
|
||||
setup.i = 1;
|
||||
setup.TOP = 0;
|
||||
setup.Y = -main.g;
|
||||
setup.Alpha = 0.9f;
|
||||
setup.Color = "#0088FF";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
wj.sc(file.toString());
|
||||
gj.sc(getClass() + ":" + e);
|
||||
}
|
||||
// 创建悬浮窗歌词的 View
|
||||
// FloatLrcviewBinding
|
||||
|
@ -144,6 +136,10 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
|
|||
}
|
||||
baocun();
|
||||
handler.post(updateSeekBar); // 在播放开始时启动更新进度
|
||||
} catch (Exception e) {
|
||||
wj.sc(file.toString());
|
||||
gj.sc(getClass() + ":" + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -211,7 +207,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
|
|||
bfqkz.mt.start();
|
||||
kg.setImageResource(R.drawable.bf);
|
||||
}
|
||||
} else if (id==R.id.lock) {
|
||||
} else if (id == R.id.lock) {
|
||||
setyc();
|
||||
} else if (id == R.id.like) {
|
||||
// bfq
|
||||
|
@ -222,7 +218,7 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
|
|||
setup.i = 2;
|
||||
params.flags = lock();
|
||||
layout.setBackground(null);
|
||||
lrcView.setAlpha(0.5f);
|
||||
lrcView.setAlpha(setup.Alpha);
|
||||
layout.findViewById(com.muqingbfq.R.id.controlLayout).setVisibility(View.GONE);
|
||||
windowManager.updateViewLayout(layout, params);
|
||||
baocun();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muqingbfq.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
|
@ -8,6 +9,9 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.muqingbfq.R;
|
||||
import com.muqingbfq.bfq;
|
||||
import com.muqingbfq.main;
|
||||
import com.muqingbfq.mq.gj;
|
||||
|
||||
public class CardImage extends MaterialCardView {
|
||||
private ImageView imageView;
|
||||
|
@ -35,7 +39,7 @@ public class CardImage extends MaterialCardView {
|
|||
|
||||
|
||||
public void setImage(Object bitmap) {
|
||||
Glide.with(getContext())
|
||||
Glide.with(this)
|
||||
.load(bitmap)
|
||||
// .apply(new RequestOptions().placeholder(R.drawable.icon))
|
||||
.into(imageView);
|
||||
|
|
|
@ -24,34 +24,45 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import com.muqingbfq.R;
|
||||
import com.muqingbfq.mq.gj;
|
||||
import com.muqingbfq.yc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LrcView extends RecyclerView {
|
||||
|
||||
static List<lrc> lrclist = new ArrayList<>();
|
||||
static List<LRC> lrclist = new ArrayList<>();
|
||||
|
||||
static class lrc {
|
||||
static class LRC {
|
||||
String lrc, tlyric;
|
||||
long time;
|
||||
|
||||
public lrc(String lrc, long time) {
|
||||
public LRC(String lrc, long time) {
|
||||
this.lrc = lrc;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public lrc(String lrc, String tlyric, long time) {
|
||||
this.lrc = lrc;
|
||||
this.tlyric = tlyric;
|
||||
this.time = time;
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public lrc setTlyric(String str) {
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
LRC lrc = (LRC) obj;
|
||||
return time == lrc.time;
|
||||
}
|
||||
public LRC setTlyric(String str) {
|
||||
this.tlyric = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return java.util.Objects.hash(time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public LrcView(Context context) {
|
||||
|
@ -81,8 +92,9 @@ public class LrcView extends RecyclerView {
|
|||
public void setTextColor(String textColor) {
|
||||
TextColor = Color.parseColor(textColor);
|
||||
}
|
||||
|
||||
|
||||
public void setLrcline(boolean lrcline) {
|
||||
Lrcline = lrcline;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (attrs != null) {
|
||||
|
@ -145,7 +157,13 @@ public class LrcView extends RecyclerView {
|
|||
}
|
||||
|
||||
public static void setLrc(String a, String b) {
|
||||
try {
|
||||
lrclist.clear();
|
||||
setLrc(a);
|
||||
setLrc(b);
|
||||
if (true) {
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(b)) {
|
||||
return;
|
||||
}
|
||||
|
@ -159,26 +177,30 @@ public class LrcView extends RecyclerView {
|
|||
String[] timeParts = timeString.split(":");
|
||||
if (timeParts.length >= 2) {
|
||||
int minute = Integer.parseInt(timeParts[0]);
|
||||
String[] secondParts = timeParts[1].split("\\.");
|
||||
String[] secondParts = timeParts[1].split("[.\\-]");
|
||||
if (secondParts.length >= 2) {
|
||||
int second = Integer.parseInt(secondParts[0]);
|
||||
int millisecond = Integer.parseInt(secondParts[1]);
|
||||
long time = (long) minute * 60 * 1000 + second * 1000L + millisecond;
|
||||
int currentLineIndex = getCurrentLineIndex(time);
|
||||
lrclist.set(currentLineIndex, lrclist.get(currentLineIndex).setTlyric(lyric));
|
||||
lrclist.set(currentLineIndex,
|
||||
lrclist.get(currentLineIndex).setTlyric(lyric));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
yc.start("LrcView setLrc :" + e + a + b);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLrc(String a) {
|
||||
lrclist.clear();
|
||||
// 去除空格
|
||||
a.trim();
|
||||
if (TextUtils.isEmpty(a)) {
|
||||
return;
|
||||
}
|
||||
a.trim();
|
||||
String[] lines = a.split("\n");
|
||||
for (String line : lines) {
|
||||
String[] parts = line.split("]");
|
||||
|
@ -188,12 +210,18 @@ public class LrcView extends RecyclerView {
|
|||
String[] timeParts = timeString.split(":");
|
||||
if (timeParts.length >= 2) {
|
||||
int minute = Integer.parseInt(timeParts[0]);
|
||||
String[] secondParts = timeParts[1].split("\\.");
|
||||
String[] secondParts = timeParts[1].split("[.\\-]");
|
||||
if (secondParts.length >= 2) {
|
||||
int second = Integer.parseInt(secondParts[0]);
|
||||
int millisecond = Integer.parseInt(secondParts[1]);
|
||||
long time = (long) minute * 60 * 1000 + second * 1000L + millisecond;
|
||||
lrclist.add(new lrc(lyric, time));
|
||||
LRC lrc = new LRC(lyric, time);
|
||||
if (lrclist.contains(lrc)) {
|
||||
int index = lrclist.indexOf(lrc);
|
||||
lrclist.get(index).setTlyric(lyric);
|
||||
} else {
|
||||
lrclist.add(lrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +272,7 @@ public class LrcView extends RecyclerView {
|
|||
|
||||
String text;
|
||||
if (lrclist.size() <= 3) {
|
||||
for (lrc a : lrclist) {
|
||||
for (LRC a : lrclist) {
|
||||
if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) {
|
||||
text = "纯音乐,请欣赏";
|
||||
holder.textView.setText(text);
|
||||
|
@ -252,7 +280,7 @@ public class LrcView extends RecyclerView {
|
|||
}
|
||||
}
|
||||
}
|
||||
lrc currentLrc = lrclist.get(currentLineIndex);
|
||||
LRC currentLrc = lrclist.get(currentLineIndex);
|
||||
text = currentLrc.lrc;
|
||||
if (currentLrc.tlyric != null) {
|
||||
text += "\n" + currentLrc.tlyric;
|
||||
|
@ -265,7 +293,7 @@ public class LrcView extends RecyclerView {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
lrc lrc = lrclist.get(position);
|
||||
LRC lrc = lrclist.get(position);
|
||||
StringBuilder stringBuffer = new StringBuilder();
|
||||
stringBuffer.append(lrc.lrc);
|
||||
if (lrc.tlyric != null) {
|
||||
|
@ -286,7 +314,7 @@ public class LrcView extends RecyclerView {
|
|||
@Override
|
||||
public int getItemCount() {
|
||||
if (lrclist.size() < 3) {
|
||||
for (lrc a : lrclist) {
|
||||
for (LRC a : lrclist) {
|
||||
if (a.time == 5940000 && a.lrc.equals("纯音乐,请欣赏")) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -314,7 +342,7 @@ public class LrcView extends RecyclerView {
|
|||
private int getCurrentLineIndex() {
|
||||
index = -1;
|
||||
for (int i = 0; i < lrclist.size(); i++) {
|
||||
lrc lineLrc = lrclist.get(i);
|
||||
LRC lineLrc = lrclist.get(i);
|
||||
if (lineLrc.time <= time) {
|
||||
index = i;
|
||||
} else {
|
||||
|
@ -327,7 +355,7 @@ public class LrcView extends RecyclerView {
|
|||
private static int getCurrentLineIndex(long time) {
|
||||
int index = 0;
|
||||
for (int i = 0; i < lrclist.size(); i++) {
|
||||
lrc lineLrc = lrclist.get(i);
|
||||
LRC lineLrc = lrclist.get(i);
|
||||
if (lineLrc.time <= time) {
|
||||
index = i;
|
||||
} else {
|
||||
|
|
|
@ -14,14 +14,17 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.muqingbfq.databinding.ActivityYcBinding;
|
||||
import com.muqingbfq.mq.gj;
|
||||
|
||||
public class yc extends AppCompatActivity {
|
||||
public static Object exception;
|
||||
public Object exception;
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ActivityYcBinding binding = ActivityYcBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
Intent intent = getIntent();
|
||||
exception = intent.getStringExtra("e");
|
||||
|
||||
String deviceModel = Build.MODEL;
|
||||
String deviceManufacturer = Build.MANUFACTURER;
|
||||
|
@ -52,8 +55,10 @@ public class yc extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public static void start(Context context, Object e) {
|
||||
yc.exception = e;
|
||||
context.startActivity(new Intent(context, yc.class));
|
||||
gj.sc(e);
|
||||
Intent intent = new Intent(context, yc.class);
|
||||
intent.putExtra("e",e.toString());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void tc(Context context, Object exception) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user