Fix lyrics loading

This commit is contained in:
h4h13 2019-12-20 00:56:06 +05:30
parent 598364b8e0
commit 1e2be0a69f
4 changed files with 56 additions and 94 deletions

View file

@ -14,10 +14,10 @@
package code.name.monkey.retromusic.util;
import android.text.TextUtils;
import android.util.Base64;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.BufferedReader;
import java.io.File;
@ -36,16 +36,17 @@ public class LyricUtil {
private static final String lrcRootPath = android.os.Environment
.getExternalStorageDirectory().toString() + "/RetroMusic/lyrics/";
private static final String TAG = "LyricUtil";
@NonNull
@Nullable
public static File writeLrcToLoc(@NonNull String title, @NonNull String artist, @NonNull String lrcContext) {
FileWriter writer = null;
try {
File file = new File(getLrcPath2(title, artist));
if (!file.exists()) {
file.mkdirs();
File file = new File(getLrcPath(title, artist));
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
writer = new FileWriter(getLrcPath2(title, artist));
writer = new FileWriter(getLrcPath(title, artist));
writer.write(lrcContext);
return file;
} catch (IOException e) {
@ -71,48 +72,17 @@ public class LyricUtil {
return file.exists();
}
public static boolean isLrcFile2Exist(@NonNull String title, @NonNull String artist) {
File file = new File(getLrcPath2(title, artist));
return file.exists();
}
@NonNull
@Nullable
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
try {
File file = new File(getLrcPath(title, artist));
File file2 = new File(getLrcPath2(title, artist));
if (file.exists()) {
return file;
} else if (file2.exists()) {
return file2;
} else {
return new File("lyric file not exist");
}
} catch (Exception dfs) {
dfs.printStackTrace();
return new File("lyric file not exist");
File file = new File(getLrcPath(title, artist));
if (file.exists()) {
return file;
} else {
return null;
}
}
public static String getLrcPath2(String title, String artist) {
if (!TextUtils.isEmpty(title)) {
String x2;
if (title.endsWith(".flac") || title.endsWith(".mogg") || title.endsWith(".alac") || title.endsWith(".aiff") || title.endsWith(".webv")) {
x2 = title.substring(0, title.length() - 5) + ".lrc";
} else {
x2 = title.substring(0, title.length() - 4) + ".lrc";
}
return x2;
}
return "";
}
public static String getLrcPath(String title, String artist) {
private static String getLrcPath(String title, String artist) {
return lrcRootPath + title + " - " + artist + ".lrc";
}
@ -135,18 +105,10 @@ public class LyricUtil {
@NonNull
public static String getStringFromFile(@NonNull String title, @NonNull String artist) throws Exception {
File file;
File file2 = new File(getLrcPath(title, artist));
File file3 = new File(getLrcPath2(title, artist));
if (file2.exists()) {
file = file2;
} else {
file = file3;
}
File file = new File(getLrcPath(title, artist));
FileInputStream fin = new FileInputStream(file);
String ret = convertStreamToString(fin);
fin.close();
// Log.d("damn2",ret);
return ret;
}