与服务器通讯由文件名改成MD5

修复专辑界面会闪退的问题
This commit is contained in:
Yutousama 2022-03-18 09:32:07 +08:00
parent aedda7b297
commit 20b80d380a
8 changed files with 31 additions and 19 deletions

View File

@ -13,7 +13,6 @@ android {
}
}
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.yutou.nas_music_player"

View File

@ -223,10 +223,10 @@ public class MusicData {
public String getPlayUrl() {
System.out.println("播放地址:" + HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY
+ "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getFileBase64());
return HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY
+ "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getFileBase64();
String url= HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY
+ "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getMd5();
System.out.println("播放地址:" +url);
return url;
}

View File

@ -15,7 +15,7 @@ public class PreviousPlayerList {
public void add(MusicData musicData){
MusicData tmp = null;
for (MusicData data : list) {
if(data.getFile().equals(musicData.getFile())){
if(data.getMd5().equals(musicData.getMd5())){
tmp=data;
}

View File

@ -304,12 +304,13 @@ public class MusicContainer {
}
private MediaMetadataCompat metadataCompat;
private String metaDataFile;
private String metaDataFile="";
public MediaMetadataCompat getMetadataCompat(MusicData data) {
if (data.getFile().equals(metaDataFile)) {
if (data.getMd5().equals(metaDataFile)) {
return metadataCompat;
}
metaDataFile=data.getMd5();
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.getTitle());
builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, data.getArtist());

View File

@ -28,6 +28,7 @@ import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
@ -178,7 +179,11 @@ public class HttpManager {
@Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
networkInterface.httpGetData(response.body().string(), response.code());
String body = response.body().string();
int code = response.code();
AppData.handler.post(() -> {
networkInterface.httpGetData(body, code);
});
}
});
}
@ -311,7 +316,9 @@ public class HttpManager {
Log.toast(MyApplication.application, "下载完成,重启生效");
if (downloadInterface != null) {
downloadInterface.onDownloadOver(oldJar);
AppData.handler.post(() -> {
downloadInterface.onDownloadOver(oldJar);
});
}
} catch (Exception e) {

View File

@ -20,6 +20,7 @@ import com.yutou.nas_music_player.Interfaces.NetworkInterface;
import com.yutou.nas_music_player.R;
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
import com.yutou.nas_music_player.containers.MusicContainer;
import com.yutou.nas_music_player.tools.AppData;
import java.util.ArrayList;
import java.util.List;
@ -34,6 +35,7 @@ public class AlbumsActivity extends AppCompatActivity {
private AppBarLayout appBarLayout;
private TextView breakApp;
private int model;//0 专辑, 1 歌手, 2 收藏
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -68,7 +70,7 @@ public class AlbumsActivity extends AppCompatActivity {
List<MusicData> list = (List<MusicData>) data;
adapter.setData(list);
adapter.notifyDataSetChanged();
if(list.isEmpty())
if (list.isEmpty())
return;
list.get(0).getImg(-1, -1, new NetworkInterface() {
@Override
@ -100,7 +102,10 @@ public class AlbumsActivity extends AppCompatActivity {
public void httpGetData(Object data, int state) {
List<MusicData> list = (List<MusicData>) data;
adapter.setData(list);
adapter.notifyDataSetChanged();
AppData.handler.post(() -> {
adapter.notifyDataSetChanged();
});
list.get(0).getImg(-1, -1, new NetworkInterface() {
@Override
public void httpGetData(Object data, int state) {
@ -134,13 +139,13 @@ public class AlbumsActivity extends AppCompatActivity {
breakApp = findViewById(R.id.breakApp);
appBarLayout = findViewById(R.id.appbar);
listView.setLayoutManager(new LinearLayoutManager(this));
adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(),model);
adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(), model);
listView.setAdapter(adapter);
appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
if(verticalOffset<-200){
breakApp.setTextColor(getResources().getColor(R.color.musicArtist,null));
}else{
breakApp.setTextColor(getResources().getColor(R.color.musicTitle,null));
if (verticalOffset < -200) {
breakApp.setTextColor(getResources().getColor(R.color.musicArtist, null));
} else {
breakApp.setTextColor(getResources().getColor(R.color.musicTitle, null));
}
});
appBarLayout.setOnClickListener(v -> finish());

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip