与服务器通讯由文件名改成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 compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig { defaultConfig {
applicationId "com.yutou.nas_music_player" applicationId "com.yutou.nas_music_player"

View File

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

View File

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

View File

@ -304,12 +304,13 @@ public class MusicContainer {
} }
private MediaMetadataCompat metadataCompat; private MediaMetadataCompat metadataCompat;
private String metaDataFile; private String metaDataFile="";
public MediaMetadataCompat getMetadataCompat(MusicData data) { public MediaMetadataCompat getMetadataCompat(MusicData data) {
if (data.getFile().equals(metaDataFile)) { if (data.getMd5().equals(metaDataFile)) {
return metadataCompat; return metadataCompat;
} }
metaDataFile=data.getMd5();
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.getTitle()); builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.getTitle());
builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, data.getArtist()); 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.time.temporal.TemporalUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -178,7 +179,11 @@ public class HttpManager {
@Override @Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { 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, "下载完成,重启生效"); Log.toast(MyApplication.application, "下载完成,重启生效");
if (downloadInterface != null) { if (downloadInterface != null) {
AppData.handler.post(() -> {
downloadInterface.onDownloadOver(oldJar); downloadInterface.onDownloadOver(oldJar);
});
} }
} catch (Exception e) { } 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.R;
import com.yutou.nas_music_player.containers.MediaBrowserHelper; import com.yutou.nas_music_player.containers.MediaBrowserHelper;
import com.yutou.nas_music_player.containers.MusicContainer; import com.yutou.nas_music_player.containers.MusicContainer;
import com.yutou.nas_music_player.tools.AppData;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -34,6 +35,7 @@ public class AlbumsActivity extends AppCompatActivity {
private AppBarLayout appBarLayout; private AppBarLayout appBarLayout;
private TextView breakApp; private TextView breakApp;
private int model;//0 专辑, 1 歌手, 2 收藏 private int model;//0 专辑, 1 歌手, 2 收藏
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -68,7 +70,7 @@ public class AlbumsActivity extends AppCompatActivity {
List<MusicData> list = (List<MusicData>) data; List<MusicData> list = (List<MusicData>) data;
adapter.setData(list); adapter.setData(list);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
if(list.isEmpty()) if (list.isEmpty())
return; return;
list.get(0).getImg(-1, -1, new NetworkInterface() { list.get(0).getImg(-1, -1, new NetworkInterface() {
@Override @Override
@ -100,7 +102,10 @@ public class AlbumsActivity extends AppCompatActivity {
public void httpGetData(Object data, int state) { public void httpGetData(Object data, int state) {
List<MusicData> list = (List<MusicData>) data; List<MusicData> list = (List<MusicData>) data;
adapter.setData(list); adapter.setData(list);
AppData.handler.post(() -> {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
});
list.get(0).getImg(-1, -1, new NetworkInterface() { list.get(0).getImg(-1, -1, new NetworkInterface() {
@Override @Override
public void httpGetData(Object data, int state) { public void httpGetData(Object data, int state) {
@ -134,13 +139,13 @@ public class AlbumsActivity extends AppCompatActivity {
breakApp = findViewById(R.id.breakApp); breakApp = findViewById(R.id.breakApp);
appBarLayout = findViewById(R.id.appbar); appBarLayout = findViewById(R.id.appbar);
listView.setLayoutManager(new LinearLayoutManager(this)); listView.setLayoutManager(new LinearLayoutManager(this));
adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(),model); adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(), model);
listView.setAdapter(adapter); listView.setAdapter(adapter);
appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> { appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
if(verticalOffset<-200){ if (verticalOffset < -200) {
breakApp.setTextColor(getResources().getColor(R.color.musicArtist,null)); breakApp.setTextColor(getResources().getColor(R.color.musicArtist, null));
}else{ } else {
breakApp.setTextColor(getResources().getColor(R.color.musicTitle,null)); breakApp.setTextColor(getResources().getColor(R.color.musicTitle, null));
} }
}); });
appBarLayout.setOnClickListener(v -> finish()); appBarLayout.setOnClickListener(v -> finish());

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { 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" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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