Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
554d9406f1 | |||
d7d5fcf065 | |||
9f5601da6b | |||
578f756635 | |||
3aef3c1504 | |||
b04bd7ca5a | |||
ed47603a29 | |||
3ef606b89e | |||
6dfaf02422 | |||
72c9ce32c0 | |||
0dedeaf301 |
@ -19,7 +19,7 @@ android {
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 32
|
||||
versionCode 1
|
||||
versionName "1.1"
|
||||
versionName "1.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@ -41,15 +41,16 @@ android {
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
namespace 'com.yutou.nas_music_player'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.android.material:material:1.6.0'
|
||||
implementation 'com.google.android.material:material:1.6.1'
|
||||
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
|
||||
implementation fileTree(dir: "libs", include: ["*.aar"])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.21"
|
||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.work:work-runtime:2.7.1'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
@ -62,7 +63,7 @@ dependencies {
|
||||
implementation 'com.alibaba:fastjson:1.2.78'
|
||||
|
||||
//noinspection GradleCompatible
|
||||
implementation 'com.android.support:support-media-compat:28.0.0'
|
||||
implementation "androidx.media:media:1.6.0"
|
||||
implementation 'androidx.palette:palette-ktx:1.0.0'
|
||||
implementation 'com.github.zrunker:ZTextView:v1.0.2'
|
||||
|
||||
@ -70,11 +71,10 @@ dependencies {
|
||||
implementation 'com.kaopiz:kprogresshud:1.2.0'
|
||||
implementation 'com.github.promeg:tinypinyin:2.0.3'
|
||||
implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.95'
|
||||
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
|
||||
|
||||
|
||||
implementation "androidx.room:room-runtime:2.2.6"
|
||||
annotationProcessor "androidx.room:room-compiler:2.2.6"
|
||||
implementation "androidx.room:room-runtime:2.4.3"
|
||||
annotationProcessor "androidx.room:room-compiler:2.4.3"
|
||||
|
||||
implementation("com.squareup.okhttp3:okhttp:4.9.3")
|
||||
|
||||
|
Binary file not shown.
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.yutou.nas_music_player">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
@ -13,6 +12,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<activity
|
||||
android:screenOrientation="fullSensor"
|
||||
android:name=".views.OpenActivity"
|
||||
|
@ -17,11 +17,13 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
import com.yutou.nas_music_player.Interfaces.DefaultNetworkInterface;
|
||||
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 com.yutou.nas_music_player.tools.ImageLoader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -69,32 +71,8 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAd
|
||||
holder.artist.setVisibility(View.VISIBLE);
|
||||
// holder.icon.setImageBitmap(ThumbnailUtils.extractThumbnail(data.getImg(), 64,64));
|
||||
if (holder.icon.getTag() == null) {
|
||||
data.getImg(AppData.minImageWidth, AppData.minImageHigh, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
Glide.with(context).load((Bitmap) data)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(holder.icon);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
ImageLoader.getInstance(context).showImage(holder.icon,data.getImageUrl(),AppData.minImageWidth,AppData.minImageHigh,true);
|
||||
}
|
||||
|
||||
holder.icon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (data.getImg(AppData.minImageWidth, AppData.minImageHigh) != null) {
|
||||
Glide.with(context).load(data.getImg(AppData.minImageWidth, AppData.minImageHigh))
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(holder.icon);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
holder.message.setText("");
|
||||
holder.play_mask.setVisibility(View.GONE);
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.yutou.nas_music_player.Adapters;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.graphics.Canvas;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class MusicItemTouchAdapterCallback extends ItemTouchHelper.Callback {
|
||||
|
||||
@Override
|
||||
public boolean isItemViewSwipeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
||||
return makeMovementFlags(0,ItemTouchHelper.START);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
||||
// super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
//System.out.println("c = " + c + ", recyclerView = " + recyclerView + ", viewHolder = " + viewHolder + ", dX = " + dX + ", dY = " + dY + ", actionState = " + actionState + ", isCurrentlyActive = " + isCurrentlyActive);
|
||||
if(isCurrentlyActive){
|
||||
ObjectAnimator animator=ObjectAnimator.ofFloat(viewHolder.itemView,"translationX",-300).setDuration(300);
|
||||
animator.start();
|
||||
ViewGroup.LayoutParams params=viewHolder.itemView.getLayoutParams();
|
||||
params.width+=300;
|
||||
viewHolder.itemView.setLayoutParams(params);
|
||||
// viewHolder.itemView.setX(dX);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,9 +7,11 @@ import android.graphics.Bitmap;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -19,15 +21,18 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
import com.yutou.nas_music_player.Interfaces.AbsObjectInterface;
|
||||
import com.yutou.nas_music_player.Interfaces.DefaultNetworkInterface;
|
||||
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
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.network.HttpManager;
|
||||
import com.yutou.nas_music_player.tools.AppData;
|
||||
import com.yutou.nas_music_player.tools.AppTools;
|
||||
import com.yutou.nas_music_player.tools.ImageLoader;
|
||||
import com.yutou.nas_music_player.tools.StringUtil;
|
||||
import com.yutou.nas_music_player.views.AlbumsActivity;
|
||||
|
||||
@ -176,7 +181,17 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
super.bind(data);
|
||||
collectionDir(data);
|
||||
topDir(data);
|
||||
itemView.setOnClickListener(v -> clickAllList(data));
|
||||
itemView.setOnClickListener(v -> {
|
||||
clickAllList(data);
|
||||
}
|
||||
);
|
||||
itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
showPOPWindows(data);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,6 +230,17 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
dislike = itemView.findViewById(R.id.dislike);
|
||||
icon = itemView.findViewById(R.id.album_image);
|
||||
play_mask = itemView.findViewById(R.id.play_mask);
|
||||
|
||||
icon.setTag("icon");
|
||||
title.setTag("title");
|
||||
artist.setTag("artist");
|
||||
message.setTag("message");
|
||||
buttons.setTag("buttons");
|
||||
collection.setTag("collection");
|
||||
top.setTag("top");
|
||||
dislike.setTag("dislike");
|
||||
play_mask.setTag("play_mask");
|
||||
|
||||
}
|
||||
|
||||
protected void collectionDir(MusicData data) {
|
||||
@ -299,23 +325,33 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
||||
intent.putExtra("model", 2);
|
||||
intent.putExtra("fid", data.getId());
|
||||
intent.putExtra("image", data.getImg(AppData.imageWidth, AppData.imageHigh));
|
||||
intent.putExtra("image", HttpManager.NetworkAPI.HOME+data.getImageUrl());
|
||||
if (clickAction != null) {
|
||||
clickAction.onClick(intent, icon);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void clickAlbum(MusicData data) {
|
||||
System.out.println("点击item");
|
||||
if (data == null)
|
||||
return;
|
||||
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
||||
intent.putExtra("model", 0);
|
||||
intent.putExtra("album", data.getAlbum());
|
||||
intent.putExtra("image", data.getImg(AppData.imageWidth, AppData.imageHigh));
|
||||
intent.putExtra("color", AppTools.getImageColor(data.getImg(AppData.minImageWidth, AppData.minImageHigh)));
|
||||
if (clickAction != null) {
|
||||
clickAction.onClick(intent, icon);
|
||||
}
|
||||
ImageLoader.getInstance(context).getImageBitmap(data.getImageUrl(), AppData.imageWidth, AppData.imageHigh, new AbsObjectInterface<Bitmap>() {
|
||||
@Override
|
||||
public void onData(Bitmap bitmap) {
|
||||
if(bitmap!=null){
|
||||
Intent intent = new Intent(itemView.getContext(), AlbumsActivity.class);
|
||||
intent.putExtra("model", 0);
|
||||
intent.putExtra("album", data.getAlbum());
|
||||
intent.putExtra("image", data.getImageUrl());
|
||||
intent.putExtra("color", AppTools.getImageColor(bitmap));
|
||||
if (clickAction != null) {
|
||||
clickAction.onClick(intent, icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -355,7 +391,7 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
public void bind(MusicData data) {
|
||||
title.setText(data.getTitle());
|
||||
artist.setText(data.getArtist());
|
||||
icon.setImageResource(R.drawable.ic_dir);
|
||||
//icon.setImageResource(R.drawable.ic_dir);
|
||||
collection.setVisibility(View.VISIBLE);
|
||||
if (!data.isDir()) {
|
||||
message.setText(data.getBitRate() + "kbps | " + data.getSampleRate() + "hz | " + data.getEncodingType());
|
||||
@ -364,17 +400,6 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
// icon.setImageBitmap(ThumbnailUtils.extractThumbnail(data.getImg(), 64,64));
|
||||
showImage(data, this);
|
||||
|
||||
icon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (data.getImg(AppData.minImageWidth, AppData.minImageHigh) != null) {
|
||||
Glide.with(MyApplication.application).load(data.getImg(AppData.minImageWidth, AppData.minImageHigh))
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(icon);
|
||||
icon.setTag("img");
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
message.setText("");
|
||||
play_mask.setVisibility(View.GONE);
|
||||
@ -427,7 +452,7 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
MusicContainer.getInstance().addTmpList(musicData);
|
||||
}
|
||||
AppTools.hideHud();
|
||||
AppTools.toast(list.size()+"首歌已添加到队列中");
|
||||
AppTools.toast(list.size() + "首歌已添加到队列中");
|
||||
|
||||
}
|
||||
|
||||
@ -449,19 +474,55 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
||||
|
||||
|
||||
protected void showImage(MusicData musicData, ViewHolder holder) {
|
||||
musicData.getImg(AppData.minImageWidth, AppData.minImageHigh, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
Glide.with(MyApplication.application).load((Bitmap) data)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(holder.icon);
|
||||
}
|
||||
ImageLoader.getInstance(context).showImage(holder.icon,musicData.getImageUrl(),AppData.minImageWidth, AppData.minImageHigh,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
System.out.println("图片下载失败");
|
||||
PopupWindow popupWindow = null;
|
||||
|
||||
protected void showPOPWindows(MusicData data) {
|
||||
Button button = new Button(context);
|
||||
button.setText("添加到列表");
|
||||
button.setOnClickListener(view -> {
|
||||
AppTools.showHud(context);
|
||||
if(!data.isDir()){
|
||||
MusicContainer.getInstance().addPlayList(data);
|
||||
AppTools.hideHud();
|
||||
AppTools.toast( "已添加到队列中");
|
||||
popupWindow.dismiss();
|
||||
return;
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("path", data.getFile());
|
||||
json.put("type", true);
|
||||
MusicContainer.getLibs().onDirMusicData(json, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data1, int state) {
|
||||
List<MusicData> list = (List<MusicData>) data1;
|
||||
int i = 0;
|
||||
for (MusicData musicData : list) {
|
||||
if (!musicData.isDir()) {
|
||||
MusicContainer.getInstance().addPlayList(musicData);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
AppTools.hideHud();
|
||||
AppTools.toast(i + "首歌已添加到队列中");
|
||||
popupWindow.dismiss();
|
||||
MusicContainer.getInstance().setPlayModel(MusicContainer.PLAY_MODEL_ORDER);
|
||||
browserHelper.getTransportControls().play();
|
||||
browserHelper.getTransportControls().skipToNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
AppTools.toast("添加失败:" + e.getMessage());
|
||||
}
|
||||
});
|
||||
});
|
||||
popupWindow = new PopupWindow(button, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
popupWindow.setOutsideTouchable(true);
|
||||
|
||||
popupWindow.showAsDropDown(itemView, 200, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,7 @@ package com.yutou.nas_music_player.Datas;
|
||||
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.ThumbnailUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas_music_player.Interfaces.DefaultNetworkInterface;
|
||||
import com.yutou.nas_music_player.Interfaces.DownloadInterface;
|
||||
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
import com.yutou.nas_music_player.R;
|
||||
import com.yutou.nas_music_player.network.HttpManager;
|
||||
import com.yutou.nas_music_player.tools.AppData;
|
||||
import com.yutou.nas_music_player.tools.AppTools;
|
||||
import com.yutou.nas_music_player.tools.NetworkTool;
|
||||
import com.yutou.nas_music_player.tools.StringUtil;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -24,7 +11,11 @@ import androidx.room.Entity;
|
||||
import androidx.room.Ignore;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import java.io.File;
|
||||
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
import com.yutou.nas_music_player.network.HttpManager;
|
||||
import com.yutou.nas_music_player.tools.AppTools;
|
||||
import com.yutou.nas_music_player.tools.StringUtil;
|
||||
|
||||
@Entity
|
||||
public class MusicData {
|
||||
@ -77,6 +68,9 @@ public class MusicData {
|
||||
@ColumnInfo
|
||||
private String md5;//确保是同一个文件
|
||||
|
||||
@Ignore
|
||||
private Bitmap bitmap;
|
||||
|
||||
public MusicData() {
|
||||
}
|
||||
|
||||
@ -220,7 +214,7 @@ public class MusicData {
|
||||
|
||||
|
||||
public String getPlayUrl() {
|
||||
String url = HttpManager.NetworkAPI.HOME + HttpManager.NetworkAPI.MUSIC_PLAY
|
||||
String url =HttpManager.NetworkAPI.MUSIC_PLAY
|
||||
+ "?random=false&token=" + HttpManager.NetworkAPI.HTTP_KEY + "&filePath=" + getMd5();
|
||||
System.out.println("播放地址:" + url);
|
||||
return url;
|
||||
@ -228,77 +222,10 @@ public class MusicData {
|
||||
|
||||
|
||||
public String getImageUrl() {
|
||||
return HttpManager.NetworkAPI.MUSIC_IMAGE + "?fileName=" + getFileBase64();
|
||||
return HttpManager.NetworkAPI.MUSIC_IMAGE + "?fileName=" + getMd5();
|
||||
}
|
||||
|
||||
|
||||
public Bitmap getImg(int width, int height) {
|
||||
return getImg(width, height, new DefaultNetworkInterface());
|
||||
}
|
||||
|
||||
public Bitmap getImg(int width, int height,@NonNull NetworkInterface networkInterface) {
|
||||
Bitmap img;
|
||||
if (StringUtil.isEmpty(file) && StringUtil.isEmpty(title) && StringUtil.isEmpty(album)) {
|
||||
img = BitmapFactory.decodeResource(MyApplication.application.getResources(), R.mipmap.ic_launcher);
|
||||
networkInterface.httpGetData(img, 0);
|
||||
return img;
|
||||
}
|
||||
String imageSaveName = (StringUtil.isEmpty(album) ? title : album) + ".png";
|
||||
img = AppTools.getSaveBitmap(imageSaveName);
|
||||
if (img != null) {
|
||||
if (width == -1 && height == -1) {
|
||||
networkInterface.httpGetData(img, 0);
|
||||
return img;
|
||||
}
|
||||
networkInterface.httpGetData(ThumbnailUtils.extractThumbnail(img, width, height), width + height);
|
||||
return ThumbnailUtils.extractThumbnail(img, width, height);
|
||||
}
|
||||
img = BitmapFactory.decodeResource(MyApplication.application.getResources(), R.mipmap.ic_launcher);
|
||||
if (isDownloadImg) {
|
||||
networkInterface.httpGetData(img, 0);
|
||||
return img;
|
||||
}
|
||||
isDownloadImg = true;
|
||||
JSONObject json = new JSONObject();
|
||||
if (!StringUtil.isEmpty(getAlbum())) {
|
||||
json.put("type", "album");
|
||||
}
|
||||
if (!StringUtil.isEmpty(getMd5())) {
|
||||
json.put("fileName", getMd5());
|
||||
} else {
|
||||
json.put("fileName", getTitle());
|
||||
}
|
||||
System.out.println("下载图片:" + HttpManager.NetworkAPI.MUSIC_IMAGE + "?" + NetworkTool.toGetSplice(json));
|
||||
HttpManager.getInstance().downloadImage(HttpManager.NetworkAPI.MUSIC_IMAGE, json, imageSaveName, "post", new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownloadOver(File oldJar) {
|
||||
isDownloadImg = false;
|
||||
AppTools.saveBitmap(oldJar, imageSaveName);
|
||||
Bitmap img = BitmapFactory.decodeFile(oldJar.getAbsolutePath());
|
||||
AppData.handler.post(() -> {
|
||||
if (width == -1 && height == -1) {
|
||||
networkInterface.httpGetData(img, 0);
|
||||
} else {
|
||||
networkInterface.httpGetData(ThumbnailUtils.extractThumbnail(img, width, height), width + height);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
isDownloadImg = false;
|
||||
Bitmap img = BitmapFactory.decodeResource(MyApplication.application.getResources(), R.mipmap.ic_launcher);
|
||||
AppData.handler.post(() -> networkInterface.httpGetData(img, 0));
|
||||
}
|
||||
});
|
||||
if (width == -1 && height == -1) {
|
||||
return img;
|
||||
}
|
||||
return ThumbnailUtils.extractThumbnail(img, width, height);
|
||||
}
|
||||
|
||||
|
||||
public int getBitRate() {
|
||||
return bitRate;
|
||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||
*/
|
||||
public class PreviousPlayerList {
|
||||
private static final int INDEX=10;//记录十条
|
||||
private List<MusicData> list;
|
||||
private final List<MusicData> list;
|
||||
public PreviousPlayerList(){
|
||||
list=new ArrayList<>();
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.yutou.nas_music_player.Interfaces;
|
||||
|
||||
public abstract class AbsObjectInterface<T> {
|
||||
public abstract void onData(T t);
|
||||
}
|
@ -11,5 +11,5 @@ public abstract class DownloadInterface {
|
||||
* @param oldJar
|
||||
*/
|
||||
public abstract void onDownloadOver(File oldJar);
|
||||
public void onError(Exception e){};
|
||||
public void onError(Exception e){}
|
||||
}
|
||||
|
@ -2,16 +2,35 @@ package com.yutou.nas_music_player;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yutou.nas_music_player.tools.ImageLoader;
|
||||
import com.yutou.nas_music_player.views.OpenActivity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
|
||||
import dalvik.system.BaseDexClassLoader;
|
||||
import dalvik.system.DexClassLoader;
|
||||
import dalvik.system.DexFile;
|
||||
|
||||
|
||||
public class MyApplication extends Application {
|
||||
public static Application application;
|
||||
private static WeakReference<Activity> activityWeakReference=null;
|
||||
public static DexClassLoader loader;
|
||||
private static WeakReference<Activity> activityWeakReference = null;
|
||||
|
||||
public static Activity getActivity() {
|
||||
return activityWeakReference.get();
|
||||
@ -21,10 +40,11 @@ public class MyApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
MyApplication.application = this;
|
||||
ImageLoader.getInstance(this);
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||
activityWeakReference=new WeakReference<>(activity);
|
||||
activityWeakReference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,5 +77,178 @@ public class MyApplication extends Application {
|
||||
|
||||
}
|
||||
});
|
||||
// dexLoader();
|
||||
System.err.println("加载版本111:" + OpenActivity.version);
|
||||
}
|
||||
|
||||
private void dexLoader() {
|
||||
File path = new File("/data/data/" + getPackageName() + "/plugs");
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
File jar = new File("/data/data/" + getPackageName() + "/plugs/classes.jar");
|
||||
System.err.println("jar = " + jar.getAbsolutePath());
|
||||
if (!jar.exists()) {
|
||||
System.out.println("进这里了");
|
||||
saveAdJar("classes.jar");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Object[] t1 = getDexElements(getClassLoader()); //获取系统类加载器的dexElements数组
|
||||
loader = new DexClassLoader(jar.getAbsolutePath(), "/data/data/" + getPackageName() + "/plugs/", null, getClassLoader());
|
||||
Object version = loader.loadClass("com.yutou.nas_music_player.views.OpenActivity").getField("version").get(null);
|
||||
System.out.println("loader version = " + version);
|
||||
Object[] t2 = getDexElements(loader); //获取jar包类加载器的dexElements数组
|
||||
saveLibPath(t1, t2); //合并两个数组,并将合并后的数组覆盖到系统类加载器
|
||||
removeLib(loader); //删掉jar包加载器的数组
|
||||
System.out.println("加载完成");
|
||||
getDexElements(getClassLoader());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并两个Elements数组并覆盖掉系统加载类的dexElements
|
||||
*
|
||||
* @param t1 合成的Elements
|
||||
* @param t2 被合并的Elements
|
||||
* @throws Exception 未知异常
|
||||
*/
|
||||
private void saveLibPath(Object[] t1, Object[] t2) throws Exception {
|
||||
//遍历BaseDexClassLoader,拿到pathList变量 源码参考: 46行
|
||||
//遍历BaseDexClassLoader源码:https://android.googlesource.com/platform/libcore/+/refs/heads/master/dalvik/src/main/java/dalvik/system/BaseDexClassLoader.java
|
||||
//DexPathList类的源码: https://android.googlesource.com/platform/libcore/+/refs/heads/master/dalvik/src/main/java/dalvik/system/DexPathList.java
|
||||
Field[] fields = BaseDexClassLoader.class.getDeclaredFields();
|
||||
Field pathListField = null;
|
||||
for (Field field : fields) {
|
||||
System.out.println("field.getName() = " + field.getName());
|
||||
if (field.getName().equals("pathList")) {
|
||||
pathListField = field;
|
||||
}
|
||||
}
|
||||
if (pathListField == null)
|
||||
return;
|
||||
pathListField.setAccessible(true);
|
||||
Object pathList = pathListField.get(getClassLoader());
|
||||
Field dexElements = pathList.getClass().getDeclaredField("dexElements"); //获取到系统类加载器的dexElements
|
||||
dexElements.setAccessible(true);
|
||||
//合并两个获取到系统类加载器的dexElements
|
||||
Object[] obj = Arrays.copyOf(t1, t1.length + t2.length);
|
||||
int index = 0;
|
||||
/* for (int i = 0; i < t2.length; i++) {
|
||||
obj[t1.length+i]=obj[index];
|
||||
obj[index++]=t2[i];
|
||||
}*/
|
||||
/* for (int i=t1.length,j=0;i<t1.length+t2.length;i++,j++){
|
||||
Array.set(obj,i,t2[j]);
|
||||
|
||||
}*/
|
||||
System.out.println("obj.length = " + obj.length);
|
||||
System.arraycopy(t2, 0, obj, t1.length, t2.length);
|
||||
Object tmp = obj[0];
|
||||
obj[0] = obj[3];
|
||||
obj[3] = tmp;
|
||||
//覆盖操作
|
||||
dexElements.set(pathList, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除类加载器的dexElements,不然会提示jar包有多个类加载器
|
||||
*
|
||||
* @param loader 被移除dexElements的加载器
|
||||
*/
|
||||
private void removeLib(ClassLoader loader) {
|
||||
try {
|
||||
Field[] fields = BaseDexClassLoader.class.getDeclaredFields();
|
||||
Field pathListField = null;
|
||||
for (Field field : fields) {
|
||||
if (field.getName().equals("pathList"))
|
||||
pathListField = field;
|
||||
}
|
||||
if (pathListField == null)
|
||||
return;
|
||||
pathListField.setAccessible(true);
|
||||
Object pathList = pathListField.get(loader);
|
||||
Field dexElements = pathList.getClass().getDeclaredField("dexElements");
|
||||
dexElements.setAccessible(true);
|
||||
dexElements.set(pathList, null);//设为null后就不要再使用这个加载器了,否则会报空指针
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类加载器的DexElements数组
|
||||
*
|
||||
* @param loader 类加载器
|
||||
* @return dexElements
|
||||
*/
|
||||
private Object[] getDexElements(ClassLoader loader) {
|
||||
System.out.println("===============start============");
|
||||
try {
|
||||
Field[] fields = BaseDexClassLoader.class.getDeclaredFields();
|
||||
Field pathListField = null;
|
||||
for (Field field : fields) {
|
||||
System.out.println(field.getName());
|
||||
if (field.getName().equals("pathList"))
|
||||
pathListField = field;
|
||||
}
|
||||
if (pathListField == null)
|
||||
return null;
|
||||
pathListField.setAccessible(true);
|
||||
Object pathList = pathListField.get(loader);
|
||||
Field dexElementsField = pathList.getClass().getDeclaredField("dexElements");
|
||||
dexElementsField.setAccessible(true);
|
||||
Object[] dexElements = (Object[]) dexElementsField.get(pathList);
|
||||
//for仅仅只是用于打印Elements类信息的
|
||||
String pathStr = "path";
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
|
||||
pathStr = "dir";
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
pathStr = "file";
|
||||
for (Object lib : dexElements) {
|
||||
System.out.println("lib = " + lib);
|
||||
Field uri_F = lib.getClass().getDeclaredField(pathStr);
|
||||
Field localName_F = lib.getClass().getDeclaredField("dexFile");
|
||||
uri_F.setAccessible(true);
|
||||
localName_F.setAccessible(true);
|
||||
File path = (File) uri_F.get(lib);
|
||||
DexFile dexFile = (DexFile) localName_F.get(lib);
|
||||
//System.out.println("uri = " + path.getAbsolutePath()+" localName = "+(dexFile==null));
|
||||
}
|
||||
System.out.println("dexElements length = " + dexElements.length);
|
||||
System.out.println("===============end============");
|
||||
return dexElements;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("===============end error============");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从assets中释放jar包资源
|
||||
*
|
||||
* @param jarName
|
||||
*/
|
||||
private void saveAdJar(String jarName) {
|
||||
AssetManager manager = this.getResources().getAssets();
|
||||
try {
|
||||
InputStream inputStream = manager.open(jarName);
|
||||
FileOutputStream outputStream = new FileOutputStream("/data/data/" + this.getPackageName() + "/plugs/" + jarName);
|
||||
if (outputStream == null) {
|
||||
return;
|
||||
|
||||
}
|
||||
int len = 0;
|
||||
byte[] bytes = new byte[inputStream.available()];
|
||||
while ((len = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
}
|
||||
dexLoader();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,21 +10,25 @@ import android.support.v4.media.session.MediaSessionCompat;
|
||||
import android.support.v4.media.session.PlaybackStateCompat;
|
||||
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
import com.yutou.nas_music_player.Interfaces.AbsObjectInterface;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
import com.yutou.nas_music_player.services.MusicService;
|
||||
import com.yutou.nas_music_player.tools.AppData;
|
||||
import com.yutou.nas_music_player.views.PlayLibsActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MediaBrowserHelper {
|
||||
private static MediaBrowserHelper helper;
|
||||
private MediaControllerCompat controllerCompat;
|
||||
private MediaBrowserCompat mMediaBrowser;
|
||||
private MediaBrowserConnectionCallback browserConnectionCallback;
|
||||
private MediaControllerCallback controllerCallback;
|
||||
private MediaBrowserSubscriptionCallback subscriptionCallback;
|
||||
private Context context;
|
||||
private final MediaBrowserConnectionCallback browserConnectionCallback;
|
||||
private final MediaControllerCallback controllerCallback;
|
||||
private final MediaBrowserSubscriptionCallback subscriptionCallback;
|
||||
private final Context context;
|
||||
|
||||
public MediaBrowserHelper(Context context) {
|
||||
private MediaBrowserHelper(Context context) {
|
||||
this.context = context;
|
||||
browserConnectionCallback = new MediaBrowserConnectionCallback();
|
||||
controllerCallback = new MediaControllerCallback();
|
||||
@ -33,6 +37,12 @@ public class MediaBrowserHelper {
|
||||
mMediaBrowser.connect();
|
||||
MusicContainer.getInstance().addBrowserHelper(this);
|
||||
}
|
||||
public static MediaBrowserHelper getInstance(){
|
||||
if(helper==null){
|
||||
helper=new MediaBrowserHelper(MyApplication.application);
|
||||
}
|
||||
return helper;
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
if (controllerCompat != null) {
|
||||
@ -61,7 +71,13 @@ public class MediaBrowserHelper {
|
||||
public void run() {
|
||||
for (MediaControllerCompat.Callback callback : callbacks) {
|
||||
if (callback != null) {
|
||||
callback.onMetadataChanged(MusicContainer.getInstance().getNowPlayMetadataCompat());
|
||||
MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface<MediaMetadataCompat>() {
|
||||
@Override
|
||||
public void onData(MediaMetadataCompat mediaMetadataCompat) {
|
||||
callback.onMetadataChanged(mediaMetadataCompat);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -70,12 +86,16 @@ public class MediaBrowserHelper {
|
||||
});
|
||||
}
|
||||
|
||||
private List<MediaControllerCompat.Callback> callbacks = new ArrayList<>();
|
||||
private final List<MediaControllerCompat.Callback> callbacks = new ArrayList<>();
|
||||
|
||||
public void regPlayListener(MediaControllerCompat.Callback playListener) {
|
||||
callbacks.add(playListener);
|
||||
}
|
||||
|
||||
public void unPlayListener(MediaControllerCompat.Callback playListener) {
|
||||
callbacks.remove(playListener);
|
||||
}
|
||||
|
||||
public void play(MusicData item) {
|
||||
MusicContainer.getInstance().setNowPlayData(item);
|
||||
getTransportControls().play();
|
||||
@ -85,17 +105,13 @@ public class MediaBrowserHelper {
|
||||
@Override
|
||||
public void onConnected() {
|
||||
super.onConnected();
|
||||
try {
|
||||
System.out.println("初始化:onConnected");
|
||||
controllerCompat = new MediaControllerCompat(context, mMediaBrowser.getSessionToken());
|
||||
controllerCompat.registerCallback(controllerCallback);
|
||||
controllerCallback.onMetadataChanged(controllerCompat.getMetadata());
|
||||
controllerCallback.onPlaybackStateChanged(controllerCompat.getPlaybackState());
|
||||
mMediaBrowser.subscribe(mMediaBrowser.getRoot(), subscriptionCallback);
|
||||
System.out.println("初始化:onConnected");
|
||||
controllerCompat = new MediaControllerCompat(context, mMediaBrowser.getSessionToken());
|
||||
controllerCompat.registerCallback(controllerCallback);
|
||||
controllerCallback.onMetadataChanged(controllerCompat.getMetadata());
|
||||
controllerCallback.onPlaybackStateChanged(controllerCompat.getPlaybackState());
|
||||
mMediaBrowser.subscribe(mMediaBrowser.getRoot(), subscriptionCallback);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,10 @@ import android.support.v4.media.MediaDescriptionCompat;
|
||||
import android.support.v4.media.MediaMetadataCompat;
|
||||
import android.support.v4.media.session.MediaSessionCompat;
|
||||
import android.support.v4.media.session.PlaybackStateCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.media.session.MediaButtonReceiver;
|
||||
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
@ -29,22 +27,24 @@ public class MediaNotificationManager {
|
||||
public static MediaNotificationManager manager;
|
||||
public static final int NOTIFICATION_ID = 412;
|
||||
private static final String CHANNEL_ID = MyApplication.application.getPackageName() + ".music_channel";
|
||||
private MusicService mService;
|
||||
private NotificationCompat.Action mPlayAction;
|
||||
private NotificationCompat.Action mPauseAction;
|
||||
private NotificationCompat.Action mNextAction;
|
||||
private NotificationCompat.Action mPrevAction;
|
||||
private NotificationManager mNotificationManager;
|
||||
private final MusicService mService;
|
||||
private final NotificationCompat.Action mPlayAction;
|
||||
private final NotificationCompat.Action mPauseAction;
|
||||
private final NotificationCompat.Action mNextAction;
|
||||
private final NotificationCompat.Action mPrevAction;
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
public static MediaNotificationManager getInstance(){
|
||||
public static MediaNotificationManager getInstance() {
|
||||
return manager;
|
||||
}
|
||||
public MusicService getService(){
|
||||
|
||||
public MusicService getService() {
|
||||
return mService;
|
||||
}
|
||||
|
||||
public MediaNotificationManager(MusicService musicService) {
|
||||
this.mService = musicService;
|
||||
manager=this;
|
||||
manager = this;
|
||||
mNotificationManager =
|
||||
(NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
@ -85,6 +85,7 @@ public class MediaNotificationManager {
|
||||
public NotificationManager getManager() {
|
||||
return mNotificationManager;
|
||||
}
|
||||
|
||||
public Notification getNotification(MediaMetadataCompat metadata,
|
||||
@NonNull PlaybackStateCompat state,
|
||||
MediaSessionCompat.Token token) {
|
||||
@ -105,12 +106,12 @@ public class MediaNotificationManager {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(mService, CHANNEL_ID);
|
||||
builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
|
||||
.setMediaSession(token)
|
||||
.setShowActionsInCompactView(0,1,2)
|
||||
.setShowActionsInCompactView(0, 1, 2)
|
||||
.setShowCancelButton(true)
|
||||
.setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(mService,PlaybackStateCompat.ACTION_STOP))
|
||||
.setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(mService, PlaybackStateCompat.ACTION_STOP))
|
||||
);
|
||||
builder.setColor(Color.BLUE);
|
||||
if(metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON)!=null){
|
||||
if (metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON) != null) {
|
||||
builder.setLargeIcon(metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON));
|
||||
}
|
||||
builder.setOngoing(true);
|
||||
@ -153,6 +154,7 @@ public class MediaNotificationManager {
|
||||
mNotificationManager.createNotificationChannel(mChannel);
|
||||
}
|
||||
}
|
||||
|
||||
private PendingIntent createContentIntent() {
|
||||
Intent openUI = new Intent(mService, MainActivity.class);
|
||||
openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
@ -4,7 +4,9 @@ import static android.media.MediaPlayer.SEEK_PREVIOUS_SYNC;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -18,24 +20,30 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
import com.yutou.nas_music_player.Datas.PreviousPlayerList;
|
||||
import com.yutou.nas_music_player.Interfaces.AbsObjectInterface;
|
||||
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
import com.yutou.nas_music_player.network.HttpManager;
|
||||
import com.yutou.nas_music_player.tools.AppData;
|
||||
import com.yutou.nas_music_player.tools.AppTools;
|
||||
import com.yutou.nas_music_player.tools.ConfigTools;
|
||||
import com.yutou.nas_music_player.tools.ImageLoader;
|
||||
import com.yutou.nas_music_player.tools.StringUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class MusicContainer {
|
||||
@ -44,19 +52,20 @@ public class MusicContainer {
|
||||
public static final int PLAY_MODEL_ONE_LOOP = 2;//单曲循环
|
||||
public static final int PLAY_MODEL_LIST_RANDOM = 3;//列表随机
|
||||
private static MusicContainer container;
|
||||
private MusicLibs libs;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private final MusicLibs libs;
|
||||
private final MediaPlayer mediaPlayer;
|
||||
private int playIndex = -1;
|
||||
private MusicData nowPlayData = null;
|
||||
private MusicLibsInitInterface initInterface;
|
||||
private List<MediaPlayer.OnCompletionListener> completionListener;
|
||||
private List<MediaBrowserHelper> browserHelpers;
|
||||
private List<MusicData> playList, tmpList;
|
||||
private LinkedHashMap<String, List<MusicData>> albumMapList;
|
||||
private LinkedHashMap<String, List<MusicData>> artistMapList;
|
||||
private LinkedHashMap<String, List<MusicData>> collectionMapList;
|
||||
private final List<MediaBrowserHelper> browserHelpers;
|
||||
private List<MusicData> playList;
|
||||
private final List<MusicData> tmpList;
|
||||
private final LinkedHashMap<String, List<MusicData>> albumMapList;
|
||||
private final LinkedHashMap<String, List<MusicData>> artistMapList;
|
||||
private final LinkedHashMap<String, List<MusicData>> collectionMapList;
|
||||
private int playModel = PLAY_MODEL_RANDOM;
|
||||
private PreviousPlayerList previousPlayerList;
|
||||
private final PreviousPlayerList previousPlayerList;
|
||||
|
||||
private MusicContainer(MusicLibsInitInterface initInterface) {
|
||||
this.initInterface = initInterface;
|
||||
@ -68,13 +77,14 @@ public class MusicContainer {
|
||||
collectionMapList = new LinkedHashMap<>();
|
||||
previousPlayerList = new PreviousPlayerList();
|
||||
browserHelpers = new ArrayList<>();
|
||||
playIndex = ConfigTools.getPreferences().getInt("playIndex", -1);
|
||||
playIndex = ConfigTools.getConfigPreferences().getInt("playIndex", -1);
|
||||
initMediaPlayer();
|
||||
libs = new MusicLibs();
|
||||
}
|
||||
|
||||
public void setPlayModel(int playModel) {
|
||||
this.playModel = playModel;
|
||||
ConfigTools.getConfigPreferences().edit().putInt("playModel", playModel).apply();
|
||||
}
|
||||
|
||||
private void initMediaPlayer() {
|
||||
@ -231,7 +241,7 @@ public class MusicContainer {
|
||||
isPause = false;
|
||||
return;
|
||||
}
|
||||
ConfigTools.getPreferences().edit().putInt("playIndex", playIndex).apply();
|
||||
ConfigTools.getConfigPreferences().edit().putInt("playIndex", playIndex).apply();
|
||||
nowPlayData = data;
|
||||
String url = data.getPlayUrl();
|
||||
previousPlayerList.add(data);
|
||||
@ -240,7 +250,7 @@ public class MusicContainer {
|
||||
mediaPlayer.stop();
|
||||
}
|
||||
mediaPlayer.reset();
|
||||
mediaPlayer.setDataSource(url);
|
||||
mediaPlayer.setDataSource(MyApplication.application, Uri.parse(url));
|
||||
mediaPlayer.prepare();
|
||||
mediaPlayer.start();
|
||||
if (playTimer == null) {
|
||||
@ -260,7 +270,7 @@ public class MusicContainer {
|
||||
ConfigTools.getPreferences().edit().putString(ConfigTools.previous_music, JSONObject.toJSONString(tmp)).apply();
|
||||
MediaNotificationManager manager = MediaNotificationManager.getInstance();
|
||||
if (manager != null) {
|
||||
manager.getService().updateNotification();
|
||||
// manager.getService().updateNotification();
|
||||
}
|
||||
tmp = null;
|
||||
} catch (IOException e) {
|
||||
@ -281,11 +291,12 @@ public class MusicContainer {
|
||||
|
||||
private Timer playTimer;
|
||||
|
||||
public MediaMetadataCompat getNowPlayMetadataCompat() {
|
||||
public void getNowPlayMetadataCompat(AbsObjectInterface<MediaMetadataCompat> objectInterface) {
|
||||
if (nowPlayData == null) {
|
||||
return null;
|
||||
objectInterface.onData(null);
|
||||
} else {
|
||||
getMetadataCompat(nowPlayData, objectInterface);
|
||||
}
|
||||
return getMetadataCompat(nowPlayData);
|
||||
}
|
||||
|
||||
public Long getYear(String year) {
|
||||
@ -306,27 +317,33 @@ public class MusicContainer {
|
||||
private MediaMetadataCompat metadataCompat;
|
||||
private String metaDataFile = "";
|
||||
|
||||
public MediaMetadataCompat getMetadataCompat(MusicData data) {
|
||||
public void getMetadataCompat(MusicData data, AbsObjectInterface<MediaMetadataCompat> objectInterface) {
|
||||
if (data.getMd5().equals(metaDataFile)) {
|
||||
return metadataCompat;
|
||||
objectInterface.onData(metadataCompat);
|
||||
return;
|
||||
}
|
||||
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());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, data.getTitle());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, data.getAlbum());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_COMPOSER, data.getComposer());
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, getYear(data.getYear()));
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, Long.parseLong(data.getTrack()));
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_DISC_NUMBER, Long.parseLong(data.getDisc_no()));
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, ((int) (data.getDurationAsDouble() * 1000)));
|
||||
if (data.getImg(AppData.minImageWidth, AppData.minImageHigh) != null) {
|
||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, data.getImg(AppData.minImageWidth, AppData.minImageHigh));
|
||||
}
|
||||
builder.putString("md5", data.getMd5());
|
||||
metadataCompat = builder.build();
|
||||
return metadataCompat;
|
||||
ImageLoader.getInstance().getImageBitmap(data.getImageUrl(), -1, -1, new AbsObjectInterface<Bitmap>() {
|
||||
@Override
|
||||
public void onData(Bitmap bitmap) {
|
||||
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, data.getTitle());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, data.getArtist());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, data.getTitle());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, data.getAlbum());
|
||||
builder.putString(MediaMetadataCompat.METADATA_KEY_COMPOSER, data.getComposer());
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, getYear(data.getYear()));
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, Long.parseLong(data.getTrack()));
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_DISC_NUMBER, Long.parseLong(data.getDisc_no()));
|
||||
builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, ((int) (data.getDurationAsDouble() * 1000)));
|
||||
if (bitmap != null) {
|
||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap);
|
||||
}
|
||||
builder.putString("md5", data.getMd5());
|
||||
metadataCompat = builder.build();
|
||||
objectInterface.onData(metadataCompat);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static MusicLibs getLibs() {
|
||||
@ -340,6 +357,11 @@ public class MusicContainer {
|
||||
mediaPlayer.pause();
|
||||
}
|
||||
|
||||
public void play() {
|
||||
isPause = false;
|
||||
mediaPlayer.start();
|
||||
}
|
||||
|
||||
public void receiverPause() {
|
||||
for (MediaBrowserHelper helper : browserHelpers) {
|
||||
if (helper.getTransportControls() != null) {
|
||||
@ -358,6 +380,9 @@ public class MusicContainer {
|
||||
tmpList.remove(0);
|
||||
return;
|
||||
}
|
||||
if (playIndex < 0 || playIndex > playList.size()) {
|
||||
playIndex = 0;
|
||||
}
|
||||
switch (playModel) {
|
||||
case PLAY_MODEL_ORDER:
|
||||
playOrder(false);
|
||||
@ -379,6 +404,9 @@ public class MusicContainer {
|
||||
*/
|
||||
public void playPrevious() {
|
||||
playIndex--;
|
||||
if (playIndex < 0) {
|
||||
playIndex = 0;
|
||||
}
|
||||
MusicData data = previousPlayerList.getMusicData();
|
||||
if (data != null) {
|
||||
play(data);
|
||||
@ -397,9 +425,8 @@ public class MusicContainer {
|
||||
playOfAllRandom();
|
||||
AppTools.toast("当前播放列表为空,随机播放");
|
||||
} else {//播放列表中的歌单
|
||||
ConfigTools.getPreferences().edit().putInt("playModel", MusicContainer.PLAY_MODEL_ORDER).apply();
|
||||
if (isRandom) {
|
||||
playIndex = new Random().nextInt(playList.size());
|
||||
playIndex = randomPlayIndex();
|
||||
} else {
|
||||
if (playList.size() > (playIndex + 1)) {
|
||||
playIndex++;
|
||||
@ -412,6 +439,14 @@ public class MusicContainer {
|
||||
}
|
||||
}
|
||||
|
||||
private int randomPlayIndex() {
|
||||
int tmp = new Random().nextInt(playList.size());
|
||||
if (tmp == playIndex) {
|
||||
return randomPlayIndex();
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单曲循环
|
||||
*/
|
||||
@ -430,10 +465,10 @@ public class MusicContainer {
|
||||
|
||||
public List<MusicData> getPlayList() {
|
||||
System.out.println("playList.size() = " + playList.size() + " tmpList.size() = " + tmpList.size());
|
||||
if (!tmpList.isEmpty()) {
|
||||
return tmpList;
|
||||
}
|
||||
return playList;
|
||||
List<MusicData> tmp = new ArrayList<>();
|
||||
tmp.addAll(tmpList);
|
||||
tmp.addAll(playList);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
@ -474,6 +509,10 @@ public class MusicContainer {
|
||||
this.playList.addAll(dataList);
|
||||
}
|
||||
|
||||
public void addPlayList(MusicData data) {
|
||||
this.playList.add(data);
|
||||
}
|
||||
|
||||
public int getPlayModel() {
|
||||
return playModel;
|
||||
}
|
||||
@ -482,6 +521,15 @@ public class MusicContainer {
|
||||
return playIndex;
|
||||
}
|
||||
|
||||
public void setPlayIndex(int i) {
|
||||
this.playIndex = i;
|
||||
}
|
||||
|
||||
public void clearPlayList() {
|
||||
playList.clear();
|
||||
tmpList.clear();
|
||||
}
|
||||
|
||||
public class MusicLibs {
|
||||
|
||||
private MusicLibs() {
|
||||
@ -505,7 +553,7 @@ public class MusicContainer {
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle("添加到收藏夹")
|
||||
.setItems((CharSequence[]) titles.toArray(new CharSequence[list.size()]), new DialogInterface.OnClickListener() {
|
||||
.setItems(titles.toArray(new CharSequence[list.size()]), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == 0) {//添加新收藏夹
|
||||
|
@ -8,7 +8,6 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bumptech.glide.load.HttpException;
|
||||
import com.yutou.nas_music_player.Interfaces.DownloadInterface;
|
||||
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
@ -24,13 +23,8 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
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;
|
||||
@ -39,7 +33,6 @@ import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttp;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
@ -50,8 +43,8 @@ public class HttpManager {
|
||||
public static String downloadPath = AppData.dir + AppData.download_dir + File.separator;
|
||||
|
||||
public static class NetworkAPI {
|
||||
public static final String HTTP_KEY = "zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||
public static String HOME = "";
|
||||
public static final String HTTP_KEY = "OHreoKn2CSlDipWV6phEupAqPIX2LJFl";
|
||||
public static String HOME = "http://nas.cnmglz.com:8000/nas";
|
||||
public static String MUSIC_LIST = HOME + "/music/list.do";
|
||||
public static String MUSIC_Album = HOME + "/music/getAlbum.do";
|
||||
public static String MUSIC_Collection_Dir_List = HOME + "/music/favorite/dir/list.do";
|
||||
@ -71,7 +64,7 @@ public class HttpManager {
|
||||
|
||||
private HttpManager() {
|
||||
System.out.println("初始化NetWork");
|
||||
httpGet("http://192.168.31.88:8000/public/version.do", new NetworkInterface() {
|
||||
/*httpGet("http://192.168.31.88:8000/public/version.do", new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
System.out.println("state = " + state);
|
||||
@ -109,7 +102,7 @@ public class HttpManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
public static HttpManager getInstance() {
|
||||
@ -250,7 +243,7 @@ public class HttpManager {
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> downloadImageList = new ArrayList<>();
|
||||
private final List<String> downloadImageList = new ArrayList<>();
|
||||
|
||||
public synchronized void downloadImage(String url, JSONObject body, String saveName, String method, DownloadInterface downloadInterface) {
|
||||
if(saveName.contains("/")){
|
||||
@ -296,7 +289,7 @@ public class HttpManager {
|
||||
Log.i("donwloadImage", "下载文件:" + url + "?" + body + " 保存文件:" + saveName);
|
||||
Log.i("downloadImageCode", response.code() + "");
|
||||
if (response.code() != 200) {
|
||||
downloadInterface.onError(new HttpException("http error = " + response.code()));
|
||||
downloadInterface.onError(new Exception("http error = " + response.code()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.media.MediaBrowserServiceCompat;
|
||||
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
import com.yutou.nas_music_player.Interfaces.AbsObjectInterface;
|
||||
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
|
||||
import com.yutou.nas_music_player.containers.MediaNotificationManager;
|
||||
import com.yutou.nas_music_player.containers.MusicContainer;
|
||||
@ -28,10 +29,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MusicService extends MediaBrowserServiceCompat {
|
||||
private final static String TAG = "MusicService";
|
||||
public MediaSessionCompat mediaSession;
|
||||
private PlaybackStateCompat.Builder stateBuilder;
|
||||
private MediaNotificationManager notificationManager;
|
||||
private int mState = PlaybackStateCompat.STATE_PLAYING;
|
||||
private String playMd5 = "";
|
||||
private MediaBrowserHelper helper;
|
||||
|
||||
private static final long MEDIA_SESSION_ACTIONS = PlaybackStateCompat.ACTION_PLAY
|
||||
| PlaybackStateCompat.ACTION_PAUSE
|
||||
@ -41,6 +45,9 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
| PlaybackStateCompat.ACTION_STOP
|
||||
| PlaybackStateCompat.ACTION_SEEK_TO;
|
||||
|
||||
MusicReceiver receiver = new MusicReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@ -55,18 +62,26 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
mediaSession.setPlaybackState(stateBuilder.build());
|
||||
mediaSession.setCallback(new MediaSessionCallback());
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, 233, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, 233, intent, PendingIntent.FLAG_MUTABLE);
|
||||
mediaSession.setSessionActivity(pi);
|
||||
setSessionToken(mediaSession.getSessionToken());
|
||||
MusicContainer.getInstance().addCompletionListener(new PlayCompletionListener());
|
||||
MediaBrowserHelper helper = new MediaBrowserHelper(this);
|
||||
helper = MediaBrowserHelper.getInstance();
|
||||
helper.regPlayListener(new MediaControllerCompat.Callback() {
|
||||
private String compat_md5 = "";
|
||||
private MediaMetadataCompat compat;
|
||||
|
||||
@Override
|
||||
public void onMetadataChanged(MediaMetadataCompat metadata) {
|
||||
super.onMetadataChanged(metadata);
|
||||
if(metadata==null){
|
||||
if (metadata == null) {
|
||||
return;
|
||||
}
|
||||
String md5 = metadata.getString("md5");
|
||||
if (compat_md5.equals(md5)) {
|
||||
return;
|
||||
}
|
||||
compat_md5 = md5;
|
||||
Notification notification = notificationManager.getNotification(metadata, builderState(0).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
@ -75,17 +90,30 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
@Override
|
||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||
super.onPlaybackStateChanged(state);
|
||||
if(mState==state.getState()){
|
||||
if (mState == state.getState()) {
|
||||
return;
|
||||
}
|
||||
mState=state.getState();
|
||||
mState = state.getState();
|
||||
MusicData data = MusicContainer.getInstance().getNowPlayData();
|
||||
MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getMetadataCompat(data);
|
||||
Notification notification = notificationManager.getNotification(metadataCompat, builderState(state.getPosition()).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
MusicContainer.getInstance().getMetadataCompat(data, new AbsObjectInterface<MediaMetadataCompat>() {
|
||||
@Override
|
||||
public void onData(MediaMetadataCompat mediaMetadataCompat) {
|
||||
Notification notification = notificationManager.getNotification(mediaMetadataCompat, builderState(state.getPosition()).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
System.out.println("注册receiver");
|
||||
registerReceiver(receiver, intentFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -97,20 +125,35 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
@Override
|
||||
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
|
||||
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
|
||||
MediaMetadataCompat compat = MusicContainer.getInstance().getNowPlayMetadataCompat();
|
||||
System.out.println(compat);
|
||||
if (compat != null) {
|
||||
MediaBrowserCompat.MediaItem mediaItem = new MediaBrowserCompat.MediaItem(compat.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
|
||||
mediaItems.add(mediaItem);
|
||||
}
|
||||
result.sendResult(mediaItems);
|
||||
MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface<MediaMetadataCompat>() {
|
||||
@Override
|
||||
public void onData(MediaMetadataCompat compat) {
|
||||
System.out.println(compat);
|
||||
if (compat != null) {
|
||||
MediaBrowserCompat.MediaItem mediaItem = new MediaBrowserCompat.MediaItem(compat.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
|
||||
mediaItems.add(mediaItem);
|
||||
}
|
||||
result.sendResult(mediaItems);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void seekToNotification(long pos) {
|
||||
|
||||
mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
|
||||
.setActions(MEDIA_SESSION_ACTIONS)
|
||||
.setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build());
|
||||
MusicData data = MusicContainer.getInstance().getNowPlayData();
|
||||
if (!playMd5.equals(data.getMd5())) {
|
||||
playMd5 = data.getMd5();
|
||||
MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface<MediaMetadataCompat>() {
|
||||
@Override
|
||||
public void onData(MediaMetadataCompat mediaMetadataCompat) {
|
||||
mediaSession.setMetadata(mediaMetadataCompat);
|
||||
updateNotification();
|
||||
mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
|
||||
.setActions(MEDIA_SESSION_ACTIONS)
|
||||
.setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public PlaybackStateCompat.Builder builderState(long position) {
|
||||
@ -153,44 +196,59 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
|
||||
public void updateNotification() {
|
||||
|
||||
MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat();
|
||||
System.out.println("更新通知栏:" + metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID));
|
||||
mediaSession.setMetadata(metadataCompat);
|
||||
mediaSession.setActive(true);
|
||||
Notification notification =
|
||||
notificationManager.getNotification(
|
||||
metadataCompat, builderState(0).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface<MediaMetadataCompat>() {
|
||||
@Override
|
||||
public void onData(MediaMetadataCompat metadataCompat) {
|
||||
System.out.println("更新通知栏:" + metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID));
|
||||
//mediaSession.setMetadata(metadataCompat);
|
||||
mediaSession.setActive(true);
|
||||
Notification notification =
|
||||
notificationManager.getNotification(
|
||||
metadataCompat, builderState(0).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public class MediaSessionCallback extends MediaSessionCompat.Callback {
|
||||
MusicReceiver receiver = new MusicReceiver();
|
||||
;
|
||||
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
||||
;
|
||||
|
||||
boolean isRegReceiver = false;
|
||||
|
||||
@Override
|
||||
public void onPlay() {
|
||||
super.onPlay();
|
||||
System.out.println("接收到播放指令");
|
||||
|
||||
registerReceiver(receiver, intentFilter);
|
||||
if (!isRegReceiver) {
|
||||
isRegReceiver = true;
|
||||
}
|
||||
mState = PlaybackStateCompat.STATE_PLAYING;
|
||||
MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat();
|
||||
mediaSession.setMetadata(metadataCompat);
|
||||
mediaSession.setActive(true);
|
||||
Notification notification = notificationManager.getNotification(metadataCompat, builderState(0).build(), getSessionToken());
|
||||
startForeground(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
MusicContainer.getInstance().play(MusicContainer.getInstance().getNowPlayData());
|
||||
MusicContainer.getInstance().getNowPlayMetadataCompat(new AbsObjectInterface<MediaMetadataCompat>() {
|
||||
@Override
|
||||
public void onData(MediaMetadataCompat metadataCompat) {
|
||||
mediaSession.setMetadata(metadataCompat);
|
||||
mediaSession.setActive(true);
|
||||
Notification notification = notificationManager.getNotification(metadataCompat, builderState(0).build(), getSessionToken());
|
||||
startForeground(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
MusicContainer.getInstance().play(MusicContainer.getInstance().getNowPlayData());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mState = PlaybackStateCompat.STATE_PAUSED;
|
||||
MusicContainer.getInstance().pause();
|
||||
System.out.println("点击暂停");
|
||||
if (helper.isPlayer()) {
|
||||
mState = PlaybackStateCompat.STATE_PAUSED;
|
||||
MusicContainer.getInstance().pause();
|
||||
} else {
|
||||
mState = PlaybackStateCompat.STATE_PLAYING;
|
||||
MusicContainer.getInstance().play();
|
||||
}
|
||||
updateNotification();
|
||||
//MusicService.this.onSeekTo(-1);
|
||||
}
|
||||
|
||||
@ -206,6 +264,7 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
@Override
|
||||
public void onSkipToNext() {
|
||||
super.onSkipToNext();
|
||||
System.out.println("播放下一曲");
|
||||
MusicContainer.getInstance().playNext();
|
||||
updateNotification();
|
||||
}
|
||||
@ -222,7 +281,7 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
super.onStop();
|
||||
mState = PlaybackStateCompat.STATE_STOPPED;
|
||||
MusicContainer.getInstance().getMediaPlayer().stop();
|
||||
unregisterReceiver(receiver);
|
||||
isRegReceiver = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@ public class AppData {
|
||||
public static String dir= MyApplication.application.getFilesDir() + File.separator;
|
||||
public static boolean isDebug=true;
|
||||
public static Handler handler=new Handler(Looper.getMainLooper());
|
||||
public static int imageWidth=400;
|
||||
public static int imageHigh=400;
|
||||
public static int minImageWidth=200;
|
||||
public static int minImageHigh=200;
|
||||
public static int imageWidth=200;
|
||||
public static int imageHigh=200;
|
||||
public static int minImageWidth=80;
|
||||
public static int minImageHigh=80;
|
||||
}
|
||||
|
@ -11,10 +11,6 @@ import android.widget.Toast;
|
||||
import androidx.palette.graphics.Palette;
|
||||
|
||||
import com.kaopiz.kprogresshud.KProgressHUD;
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.yutou.nas_music_player.MyApplication;
|
||||
import com.yutou.nas_music_player.R;
|
||||
|
||||
@ -24,6 +20,7 @@ import java.security.MessageDigest;
|
||||
|
||||
public class AppTools {
|
||||
private static KProgressHUD hud;
|
||||
private static ImageLoader imageLoader;
|
||||
|
||||
public static synchronized void showHud(Context context) {
|
||||
hideHud();
|
||||
@ -88,7 +85,7 @@ public class AppTools {
|
||||
}
|
||||
|
||||
private static String bytesToHexString(byte[] src) {
|
||||
StringBuilder stringBuilder = new StringBuilder("");
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (src == null || src.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
@ -103,29 +100,6 @@ public class AppTools {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private static DisplayImageOptions initDisplayOptions() {
|
||||
DisplayImageOptions.Builder displayImageOptionsBuilder = new DisplayImageOptions.Builder();
|
||||
displayImageOptionsBuilder.cacheInMemory(false);
|
||||
displayImageOptionsBuilder.cacheOnDisk(true);
|
||||
displayImageOptionsBuilder.showImageForEmptyUri(R.drawable.ic_launcher_background);
|
||||
displayImageOptionsBuilder.showImageOnFail(R.mipmap.ic_launcher);
|
||||
return displayImageOptionsBuilder.build();
|
||||
}
|
||||
|
||||
public static ImageLoader initImageLoader(Context context) {
|
||||
|
||||
ImageLoader imageLoader = ImageLoader.getInstance();
|
||||
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context);
|
||||
File cachePath = new File(context.getFilesDir().getAbsolutePath() + "/cache/");
|
||||
if (!cachePath.exists()) {
|
||||
cachePath.exists();
|
||||
}
|
||||
builder.diskCache(new UnlimitedDiskCache(cachePath));
|
||||
builder.defaultDisplayImageOptions(initDisplayOptions());
|
||||
|
||||
imageLoader.init(builder.build());
|
||||
return imageLoader;
|
||||
}
|
||||
|
||||
public static String getUrlBase64(String text) {
|
||||
return new String(Base64.encode(text.getBytes(), Base64.DEFAULT)).replace("\n", "");
|
||||
@ -135,7 +109,7 @@ public class AppTools {
|
||||
AppData.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(MyApplication.application, s, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(MyApplication.application, s, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -10,5 +10,9 @@ public class ConfigTools {
|
||||
public static SharedPreferences getPreferences(){
|
||||
return MyApplication.application.getSharedPreferences("app_config", Context.MODE_PRIVATE);
|
||||
}
|
||||
public static SharedPreferences getConfigPreferences(){
|
||||
return MyApplication.application.getSharedPreferences("config", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
package com.yutou.nas_music_player.tools;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.bumptech.glide.request.FutureTarget;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.yutou.nas_music_player.Interfaces.AbsObjectInterface;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
|
||||
public class ImageLoader {
|
||||
private static ImageLoader manager;
|
||||
private Context context;
|
||||
|
||||
private ImageLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public static ImageLoader getInstance(Context context) {
|
||||
if (manager == null) {
|
||||
manager = new ImageLoader(context);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static ImageLoader getInstance() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public void showImage(ImageView imageView, String url, int imageWidth, int imageHigh, boolean isRounded, boolean isBlurTransformation) {
|
||||
Log.w("图片地址", "url: " + url);
|
||||
RequestBuilder<Drawable> builder = Glide.with(context)
|
||||
.load(url)
|
||||
.placeholder(imageView.getDrawable());
|
||||
if (imageWidth != -1 && imageHigh != -1) {
|
||||
builder = builder.override(imageWidth, imageHigh);
|
||||
}
|
||||
if (isRounded) {
|
||||
builder = builder.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)));
|
||||
}
|
||||
if (isBlurTransformation) {
|
||||
builder = builder.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)));
|
||||
}
|
||||
builder.into(imageView);
|
||||
}
|
||||
|
||||
public void showImage(ImageView imageView, String url) {
|
||||
showImage(imageView, url, -1, -1, false, false);
|
||||
}
|
||||
|
||||
public void showImage(ImageView imageView, String url, int imageWidth, int imageHigh) {
|
||||
showImage(imageView, url, imageWidth, imageHigh, false, false);
|
||||
}
|
||||
|
||||
public void showImage(ImageView imageView, String url, int imageWidth, int imageHigh, boolean isRounded) {
|
||||
showImage(imageView, url, imageWidth, imageHigh, isRounded, false);
|
||||
}
|
||||
|
||||
public void getImageBitmap(String url, int imageWidth, int imageHigh, AbsObjectInterface<Bitmap> objectInterface) {
|
||||
RequestBuilder<Bitmap> builder = Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url);
|
||||
if (imageWidth != -1 && imageHigh != -1) {
|
||||
builder = builder.override(imageWidth, imageHigh);
|
||||
}
|
||||
builder.into(new CustomTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||
objectInterface.onData(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import java.io.StringWriter;
|
||||
*/
|
||||
public class Log {
|
||||
public static boolean isDebug = AppData.isDebug;
|
||||
private static boolean LogPrint = false;
|
||||
private static final boolean LogPrint = false;
|
||||
|
||||
public static String getErrorLog(Exception e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
@ -29,7 +29,7 @@ public class Log {
|
||||
+ "SDK_Version = " + Build.VERSION.SDK_INT + "\n"
|
||||
+ "files = " + files
|
||||
+ "Error = \n";
|
||||
return str + writer.toString();
|
||||
return str + writer;
|
||||
}
|
||||
|
||||
private static void printOrInfo(String string) {
|
||||
@ -68,7 +68,7 @@ public class Log {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(writer);
|
||||
e.printStackTrace(printWriter);
|
||||
printOrError("[" + title + "]" + writer.toString());
|
||||
printOrError("[" + title + "]" + writer);
|
||||
}
|
||||
|
||||
public static void toast(final Context context, final String string) {
|
||||
|
@ -34,7 +34,7 @@ import static com.yutou.nas_music_player.tools.NetworkTool.NetworkAPI.HTTP_KEY;
|
||||
public class NetworkTool {
|
||||
|
||||
public static class NetworkAPI {
|
||||
public static final String HTTP_KEY = "zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||
public static final String HTTP_KEY = "OHreoKn2CSlDipWV6phEupAqPIX2LJFl";
|
||||
public static String HOME = "";
|
||||
public static String MUSIC_LIST = HOME + "/music/list.do";
|
||||
public static String MUSIC_Album = HOME + "/music/getAlbum.do";
|
||||
@ -187,7 +187,7 @@ public class NetworkTool {
|
||||
|
||||
}
|
||||
|
||||
private Map<JSONObject, Integer> map = Collections.synchronizedMap(new HashMap<JSONObject, Integer>());
|
||||
private final Map<JSONObject, Integer> map = Collections.synchronizedMap(new HashMap<JSONObject, Integer>());
|
||||
|
||||
public void httpPost(final String url, final JSONObject body, final NetworkInterface networkInterface) {
|
||||
if (!url.startsWith("http:") && !StringUtil.isEmpty(HOME)) {
|
||||
@ -230,7 +230,7 @@ public class NetworkTool {
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
Log.i(TAG, "[域名]" + url + " = [body]" + body.toString() + " -> [接收] " + str);
|
||||
Log.i(TAG, "[域名]" + url + " = [body]" + body + " -> [接收] " + str);
|
||||
final String finalStr = str.toString();
|
||||
|
||||
// Log.i(TAG + "[" + url + "?" + toGetSplice(body) + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
|
||||
@ -316,7 +316,7 @@ public class NetworkTool {
|
||||
download(url, new JSONObject(), saveName, "GET", null);
|
||||
}
|
||||
|
||||
private List<String> downloadImageList = new ArrayList<>();
|
||||
private final List<String> downloadImageList = new ArrayList<>();
|
||||
|
||||
public synchronized void downloadImage(final String url, final JSONObject body, final String saveName, String method, final DownloadInterface downloadInterface) {
|
||||
System.out.println(">>>>>>>>>>" + url);
|
||||
@ -342,7 +342,7 @@ public class NetworkTool {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url + "?" + toGetSplice(body)).openConnection();
|
||||
|
||||
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||
if (method.toLowerCase().equals("post")) {
|
||||
if (method.equalsIgnoreCase("post")) {
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
@ -414,7 +414,7 @@ public class NetworkTool {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
|
||||
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||
if (method.toLowerCase().equals("post")) {
|
||||
if (method.equalsIgnoreCase("post")) {
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
|
@ -5,6 +5,7 @@ import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.media.session.MediaControllerCompat;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
@ -25,7 +26,7 @@ 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 com.yutou.nas_music_player.tools.AppTools;
|
||||
import com.yutou.nas_music_player.tools.ImageLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -41,6 +42,7 @@ public class AlbumsActivity extends AppCompatActivity {
|
||||
private TextView breakApp;
|
||||
private Button playAll;
|
||||
private int model;//0 专辑, 1 歌手, 2 收藏
|
||||
private PlayListener playListener;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -59,20 +61,19 @@ public class AlbumsActivity extends AppCompatActivity {
|
||||
default:
|
||||
finish();
|
||||
}
|
||||
Bitmap image=getIntent().getParcelableExtra("image");
|
||||
if(image!=null){
|
||||
album_image.setImageBitmap(image);
|
||||
Glide.with(AlbumsActivity.this).load(image)
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
|
||||
.into(image_background);
|
||||
}else{
|
||||
String imageUrl = getIntent().getStringExtra("image");
|
||||
if (imageUrl != null) {
|
||||
ImageLoader.getInstance(this).showImage(album_image, imageUrl, -1, -1, true);
|
||||
ImageLoader.getInstance(this).showImage(image_background, imageUrl, -1, -1, false,true);
|
||||
} else {
|
||||
album_image.setImageResource(R.mipmap.ic_launcher);
|
||||
Glide.with(AlbumsActivity.this).load(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
|
||||
Glide.with(AlbumsActivity.this).load(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
|
||||
.into(image_background);
|
||||
}
|
||||
browserHelper = new MediaBrowserHelper(this);
|
||||
browserHelper.regPlayListener(new PlayListener());
|
||||
playListener = new PlayListener();
|
||||
browserHelper = MediaBrowserHelper.getInstance();
|
||||
browserHelper.regPlayListener(playListener);
|
||||
adapter.setPlayListener(browserHelper);
|
||||
listView.setBackgroundColor(getIntent().getIntExtra("color", Color.parseColor("#bbbbbb")));
|
||||
playAll.setBackgroundColor(getIntent().getIntExtra("color", Color.parseColor("#bbbbbb")));
|
||||
@ -93,20 +94,7 @@ public class AlbumsActivity extends AppCompatActivity {
|
||||
adapter.notifyDataSetChanged();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
list.get(0).getImg(AppData.imageWidth,AppData.imageHigh, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
album_image.setImageBitmap((Bitmap) data);
|
||||
Glide.with(AlbumsActivity.this).load(data)
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
|
||||
.into(image_background);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
ImageLoader.getInstance(AlbumsActivity.this).showImage(image_background, list.get(0).getImageUrl(), AppData.imageWidth, AppData.imageHigh, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,7 +130,7 @@ public class AlbumsActivity extends AppCompatActivity {
|
||||
listView = findViewById(R.id.album_list);
|
||||
breakApp = findViewById(R.id.breakApp);
|
||||
appBarLayout = findViewById(R.id.appbar);
|
||||
playAll=findViewById(R.id.playAll);
|
||||
playAll = findViewById(R.id.playAll);
|
||||
listView.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new AlbumsRecyclerAdapter(AlbumsActivity.this, new ArrayList<>(), model);
|
||||
listView.setAdapter(adapter);
|
||||
@ -156,7 +144,7 @@ public class AlbumsActivity extends AppCompatActivity {
|
||||
breakApp.setOnClickListener(v -> finish());
|
||||
playAll.setOnClickListener(v -> {
|
||||
MusicContainer.getInstance().setPlayList(new ArrayList<>(adapter.getMusicDatas()));
|
||||
MusicContainer.getInstance().playNext();
|
||||
browserHelper.play(adapter.getMusicDatas().get(0));
|
||||
});
|
||||
}
|
||||
|
||||
@ -164,6 +152,6 @@ public class AlbumsActivity extends AppCompatActivity {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
adapter.onStop();
|
||||
browserHelper.onStop();
|
||||
browserHelper.unPlayListener(playListener);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import androidx.core.util.Pair;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.yutou.nas_music_player.Adapters.MusicLibsAdapter;
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
@ -94,9 +95,15 @@ public class MusicLibsFragment extends Fragment {
|
||||
getContext().startActivity(intent, bundle);
|
||||
});
|
||||
adapter.notifyDataSetChanged();
|
||||
if(MusicContainer.getInstance().getNowPlayData()==null){
|
||||
return;
|
||||
}
|
||||
closeDefaultAnimator();
|
||||
}
|
||||
/* * 关闭默认局部刷新动画 ,this代表recycleview*/
|
||||
public void closeDefaultAnimator() {
|
||||
listView.getItemAnimator().setAddDuration(0);
|
||||
listView.getItemAnimator().setChangeDuration(0);
|
||||
listView.getItemAnimator().setMoveDuration(0);
|
||||
listView.getItemAnimator().setRemoveDuration(0);
|
||||
((SimpleItemAnimator) listView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
}
|
||||
|
||||
public MusicLibsAdapter getAdapter() {
|
||||
@ -122,7 +129,7 @@ public class MusicLibsFragment extends Fragment {
|
||||
}
|
||||
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
private String musicPath = "root";
|
||||
private final String musicPath = "root";
|
||||
|
||||
public void initData() {
|
||||
AppTools.showHud(context);
|
||||
|
@ -15,8 +15,10 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -33,12 +35,14 @@ import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.yutou.nas_music_player.Adapters.MusicLibsAdapter;
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
import com.yutou.nas_music_player.Interfaces.DefaultNetworkInterface;
|
||||
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 com.yutou.nas_music_player.tools.AppTools;
|
||||
import com.yutou.nas_music_player.tools.ConfigTools;
|
||||
import com.yutou.nas_music_player.tools.ImageLoader;
|
||||
import com.yutou.popdialog.POPDialog;
|
||||
|
||||
import java.util.List;
|
||||
@ -58,6 +62,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private TextView positionTime, durationTime, bitRate, playIndex;
|
||||
private SeekBar seekBar;
|
||||
private Handler handler;
|
||||
private PlayListener playListener;
|
||||
|
||||
private GestureDetectorCompat touch;
|
||||
|
||||
@ -69,48 +74,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
handler = new Handler(Looper.myLooper());
|
||||
initView();
|
||||
play.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (browserHelper.isPlayer()) {
|
||||
browserHelper.getTransportControls().pause();
|
||||
} else {
|
||||
browserHelper.getTransportControls().play();
|
||||
}
|
||||
}
|
||||
});
|
||||
play.setOnClickListener(v -> handler.post(() -> {
|
||||
|
||||
if (browserHelper.isPlayer()) {
|
||||
browserHelper.getTransportControls().pause();
|
||||
} else {
|
||||
browserHelper.getTransportControls().play();
|
||||
}
|
||||
});
|
||||
next.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
browserHelper.getTransportControls().skipToNext();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
previous.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
browserHelper.getTransportControls().skipToPrevious();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
next.setOnClickListener(v -> handler.post(() -> browserHelper.getTransportControls().skipToNext()));
|
||||
previous.setOnClickListener(v -> handler.post(() -> browserHelper.getTransportControls().skipToPrevious()));
|
||||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
@ -124,31 +97,25 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (browserHelper.getTransportControls() != null) {
|
||||
browserHelper.getTransportControls().seekTo(MainActivity.this.seekBar.getProgress());
|
||||
}
|
||||
handler.post(() -> {
|
||||
if (browserHelper.getTransportControls() != null) {
|
||||
browserHelper.getTransportControls().seekTo(MainActivity.this.seekBar.getProgress());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
playModel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int model = (int) playModel.getTag();
|
||||
if (model == MusicContainer.PLAY_MODEL_LIST_RANDOM) {
|
||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, true);
|
||||
return;
|
||||
}
|
||||
setPlayModelButton(model + 1, true);
|
||||
playModel.setOnClickListener(v -> {
|
||||
int model = (int) playModel.getTag();
|
||||
if (model == MusicContainer.PLAY_MODEL_LIST_RANDOM) {
|
||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, true);
|
||||
return;
|
||||
}
|
||||
setPlayModelButton(model + 1, true);
|
||||
});
|
||||
|
||||
browserHelper = new MediaBrowserHelper(this);
|
||||
browserHelper.regPlayListener(new PlayListener());
|
||||
playListener = new PlayListener();
|
||||
browserHelper = MediaBrowserHelper.getInstance();
|
||||
browserHelper.regPlayListener(playListener);
|
||||
|
||||
initData();
|
||||
}
|
||||
@ -190,26 +157,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
int seconds = (int) (data.getDurationAsDouble() % 60);
|
||||
durationTime.setText(String.format(Locale.CHINA, "%02d", minutes) + ":"
|
||||
+ String.format(Locale.CHINA, "%02d", seconds));
|
||||
int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
int model = ConfigTools.getConfigPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
setPlayModelButton(model);
|
||||
if (data.getImg(AppData.imageWidth, AppData.imageHigh) != null) {
|
||||
setImage(data);
|
||||
} else {
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (data.getImg(AppData.imageWidth, AppData.imageHigh) != null) {
|
||||
AppData.handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setImage(data);
|
||||
}
|
||||
});
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 0, 100);
|
||||
}
|
||||
setImage(data);
|
||||
|
||||
}
|
||||
|
||||
@ -243,19 +193,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
break;
|
||||
default:
|
||||
setPlayModelButton(MusicContainer.PLAY_MODEL_RANDOM, isButton);
|
||||
return;
|
||||
}
|
||||
ConfigTools.getPreferences().edit().putInt("playModel", model).apply();
|
||||
}
|
||||
|
||||
private void setImage(MusicData data) {
|
||||
// setBarColor(data.getImageColor());
|
||||
Glide.with(this).load(data.getImg(AppData.imageWidth, AppData.imageHigh))
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(album_image);
|
||||
Glide.with(this).load(data.getImg(AppData.minImageWidth, AppData.minImageHigh))
|
||||
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
|
||||
.into(background_image);
|
||||
ImageLoader.getInstance(this).showImage(album_image, data.getImageUrl(), AppData.imageWidth, AppData.imageHigh, true);
|
||||
ImageLoader.getInstance(this).showImage(background_image, data.getImageUrl(),AppData.imageWidth, AppData.imageHigh, false, true);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
@ -274,7 +218,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
playModel = findViewById(R.id.playModel);
|
||||
playIndex = findViewById(R.id.playIndex);
|
||||
touch = new GestureDetectorCompat(this, new MyTouch());
|
||||
int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
int model = ConfigTools.getConfigPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM);
|
||||
setPlayModelButton(model);
|
||||
}
|
||||
|
||||
@ -287,6 +231,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (browserHelper != null) {
|
||||
browserHelper.unPlayListener(playListener);
|
||||
browserHelper.onStop();
|
||||
browserHelper = null;
|
||||
}
|
||||
@ -321,13 +266,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void toPlayList() {
|
||||
Pair<View, String> pImage = Pair.create((View) album_image, "main_album_image");
|
||||
Pair<View, String> pPrevious = Pair.create((View) previous, "previous");
|
||||
Pair<View, String> pPlay = Pair.create((View) play, "play");
|
||||
Pair<View, String> pNext = Pair.create((View) next, "next");
|
||||
Pair<View, String> pTitle = Pair.create((View) title, "title");
|
||||
Pair<View, String> pArtist = Pair.create((View) artist, "artist");
|
||||
Pair<View, String> pBar = Pair.create((View) seekBar, "bar");
|
||||
Pair<View, String> pImage = Pair.create(album_image, "main_album_image");
|
||||
Pair<View, String> pPrevious = Pair.create(previous, "previous");
|
||||
Pair<View, String> pPlay = Pair.create(play, "play");
|
||||
Pair<View, String> pNext = Pair.create(next, "next");
|
||||
Pair<View, String> pTitle = Pair.create(title, "title");
|
||||
Pair<View, String> pArtist = Pair.create(artist, "artist");
|
||||
Pair<View, String> pBar = Pair.create(seekBar, "bar");
|
||||
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this,
|
||||
pImage,
|
||||
pPrevious,
|
||||
@ -351,6 +296,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
List<MusicData> playList = MusicContainer.getInstance().getPlayList();
|
||||
POPDialog dialog = new POPDialog(this);
|
||||
RecyclerView recyclerView = null;
|
||||
Button clear = new Button(this);
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
clear.setText("清空列表");
|
||||
dialog.enableExitButton(true);
|
||||
if (playList.isEmpty()) {
|
||||
dialog.setTitle("播放列表");
|
||||
@ -358,14 +307,23 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else {
|
||||
dialog.setTitle("播放列表:" + playList.size());
|
||||
MusicLibsAdapter adapter = new MusicLibsAdapter(this);
|
||||
// ItemTouchHelper touchHelper=new ItemTouchHelper(new MusicItemTouchAdapterCallback());
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
recyclerView = new RecyclerView(this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setLayoutParams(params);
|
||||
recyclerView.setAdapter(adapter);
|
||||
// touchHelper.attachToRecyclerView(recyclerView);
|
||||
adapter.setData(playList);
|
||||
adapter.setBrowserHelper(browserHelper);
|
||||
dialog.setContentView(recyclerView);
|
||||
clear.setOnClickListener(view -> {
|
||||
MusicContainer.getInstance().clearPlayList();
|
||||
AppTools.toast("列表已清空");
|
||||
dialog.dismiss();
|
||||
});
|
||||
layout.addView(clear);
|
||||
layout.addView(recyclerView);
|
||||
dialog.setContentView(layout);
|
||||
}
|
||||
dialog.show();
|
||||
}
|
||||
@ -375,8 +333,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||
super.onPlaybackStateChanged(state);
|
||||
//System.out.println("播放状态变化:" + state.getPosition() + " " + seekBar.getMax());
|
||||
if (state.getState() == PlaybackStateCompat.STATE_PLAYING) {
|
||||
//System.out.println("[MainActivity]播放状态变化:" + state.getPosition() + " " + seekBar.getMax()+" state.getState() = "+state.getState()+" isPlay = "+browserHelper.isPlayer());
|
||||
if (state.getState() == PlaybackStateCompat.STATE_PLAYING || browserHelper.isPlayer()) {
|
||||
int duration = (int) (state.getPosition() / 1000);
|
||||
int minutes = duration / 60;
|
||||
int seconds = duration % 60;
|
||||
@ -396,7 +354,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
super.onMetadataChanged(metadata);
|
||||
String md5 = null;
|
||||
try {
|
||||
System.out.println("播放歌曲变换:" + metadata.getString("md5"));
|
||||
System.out.println("[MainActivity]播放歌曲变换:" + metadata.getString("md5"));
|
||||
md5 = metadata.getString("md5");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
@ -409,13 +367,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onSessionDestroyed() {
|
||||
super.onSessionDestroyed();
|
||||
System.out.println("连接被销毁");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged(List<MediaSessionCompat.QueueItem> queue) {
|
||||
super.onQueueChanged(queue);
|
||||
System.out.println("不知道是啥变换了");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,128 @@
|
||||
package com.yutou.nas_music_player.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.GestureDetectorCompat;
|
||||
|
||||
public class MyItemLayout extends LinearLayout {
|
||||
private GestureDetectorCompat touch;
|
||||
private int mTotalLength;
|
||||
|
||||
public MyItemLayout(Context context) {
|
||||
super(context);
|
||||
initTouch(context);
|
||||
}
|
||||
|
||||
public MyItemLayout(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initTouch(context);
|
||||
}
|
||||
|
||||
private void initTouch(Context context) {
|
||||
touch = new GestureDetectorCompat(context, new GestureDetector.SimpleOnGestureListener() {
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
System.out.println("MyItemLayout.onFling");
|
||||
return super.onFling(e1, e2, velocityX, velocityY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
System.out.println("MyItemLayout.onDown");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
System.out.println("MyItemLayout.onScroll");
|
||||
MyItemLayout.this.setX(MyItemLayout.this.getX()+e2.getX());
|
||||
return super.onScroll(e1, e2, distanceX, distanceY);
|
||||
}
|
||||
/* @Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
float y = e2.getY() - e1.getY();
|
||||
System.out.println("执行动画");
|
||||
if (Math.abs(y) < 200) {
|
||||
float x = e2.getX() - e1.getX();
|
||||
ObjectAnimator animator = new ObjectAnimator();
|
||||
animator.setTarget(MyItemLayout.this);
|
||||
animator.setPropertyName("translationX");
|
||||
animator.setDuration(300);
|
||||
if (x < 0) {
|
||||
animator.setFloatValues(-(mTotalLength - getRight()));
|
||||
} else {
|
||||
animator.setFloatValues(0);
|
||||
}
|
||||
animator.start();
|
||||
return true;
|
||||
}
|
||||
return super.onScroll(e1, e2, distanceX, distanceY);
|
||||
}*/
|
||||
});
|
||||
}
|
||||
|
||||
private final boolean down = false;
|
||||
private final boolean up = false;
|
||||
private final boolean move = false;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
boolean tmp = super.onTouchEvent(ev);
|
||||
/* int action = ev.getAction();
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
down = true;
|
||||
move = false;
|
||||
up = false;
|
||||
} else if (action == MotionEvent.ACTION_UP) {
|
||||
down = false;
|
||||
move = false;
|
||||
up = true;
|
||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||
down = true;
|
||||
move = true;
|
||||
up = false;
|
||||
}
|
||||
System.out.println("action = " + action + " down = " + down + " move = " + move + " up = " + up);
|
||||
if (down && !up && !move) {
|
||||
return false;
|
||||
} else if (down && move && !up) {
|
||||
System.out.println("移动啦");
|
||||
boolean clickVal = touch.onTouchEvent(ev);
|
||||
return true;
|
||||
} else if (down && up && !move) {
|
||||
return false;
|
||||
}
|
||||
AppTools.toast(tmp+"");*/
|
||||
tmp=true;
|
||||
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
System.out.println("进触摸");
|
||||
boolean clickVal = touch.onTouchEvent(ev);
|
||||
return clickVal;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int _left, int top, int _right, int bottom) {
|
||||
//right+=300;
|
||||
super.onLayout(changed, _left, top, _right, bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
mTotalLength += getChildAt(i).getWidth();
|
||||
}
|
||||
System.out.println("mTotalLength = " + mTotalLength);
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,9 @@ package com.yutou.nas_music_player.views;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
@ -9,22 +12,55 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.yutou.nas_music_player.R;
|
||||
import com.yutou.nas_music_player.containers.MusicContainer;
|
||||
import com.yutou.nas_music_player.tools.AppTools;
|
||||
|
||||
import cc.ibooker.ztextviewlib.MarqueeTextView;
|
||||
|
||||
public class OpenActivity extends AppCompatActivity {
|
||||
TextView textView;
|
||||
public static String version="1.0";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_open);
|
||||
textView=findViewById(R.id.textView);
|
||||
MusicContainer.getInstance(new MusicContainer.MusicLibsInitInterface() {
|
||||
@Override
|
||||
public void init() {
|
||||
Intent intent=new Intent(OpenActivity.this,MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(intent);
|
||||
OpenActivity.this.finish();
|
||||
}
|
||||
});
|
||||
if (false) {
|
||||
setContentView(R.layout.layout_music_libs_item);
|
||||
System.out.println("ok");
|
||||
ImageButton a,b,c;
|
||||
MarqueeTextView textView=findViewById(R.id.title);
|
||||
LinearLayout layout=findViewById(R.id.layout);
|
||||
a=findViewById(R.id.dislike);
|
||||
b=findViewById(R.id.collection);
|
||||
c=findViewById(R.id.top);
|
||||
layout.setTag("layout");
|
||||
a.setTag("a");
|
||||
b.setTag("b");
|
||||
c.setTag("c");
|
||||
textView.setText(version);
|
||||
a.setOnClickListener(new Click());
|
||||
b.setOnClickListener(new Click());
|
||||
c.setOnClickListener(new Click());
|
||||
layout.setOnClickListener(new Click());
|
||||
System.out.println("version = " + version);
|
||||
} else {
|
||||
setContentView(R.layout.activity_open);
|
||||
textView = findViewById(R.id.textView);
|
||||
MusicContainer.getInstance(new MusicContainer.MusicLibsInitInterface() {
|
||||
@Override
|
||||
public void init() {
|
||||
Intent intent = new Intent(OpenActivity.this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(intent);
|
||||
OpenActivity.this.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private static class Click implements View.OnClickListener{
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AppTools.toast("click view = "+view.getTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ 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 com.yutou.nas_music_player.tools.ImageLoader;
|
||||
import com.yutou.nas_music_player.views.Fragments.MusicLibsFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -50,14 +51,14 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
|
||||
private TabLayout tabLayout;
|
||||
private ViewPager2 viewPager;
|
||||
private int index = 0;
|
||||
private final int index = 0;
|
||||
PlayListener playListener = new PlayListener();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_play_list);
|
||||
PlayListener playListener = new PlayListener();
|
||||
browserHelper = new MediaBrowserHelper(this);
|
||||
browserHelper = MediaBrowserHelper.getInstance();
|
||||
browserHelper.regPlayListener(playListener);
|
||||
initView();
|
||||
bar_pos = getIntent().getIntExtra("bar_pos", 0);
|
||||
@ -107,6 +108,7 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
List<MusicLibsFragment> fragments;
|
||||
|
||||
private void initView() {
|
||||
play = findViewById(R.id.collection);
|
||||
next = findViewById(R.id.top);
|
||||
@ -117,11 +119,11 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
progressBar = findViewById(R.id.progressBar);
|
||||
tabLayout = findViewById(R.id.tabLayout);
|
||||
viewPager = findViewById(R.id.viewPager);
|
||||
fragments=new ArrayList<>();
|
||||
fragments.add(new MusicLibsFragment(this,MusicLibsAdapter.LIBS_MODEL_ALL));
|
||||
fragments.add(new MusicLibsFragment(this,MusicLibsAdapter.LIBS_MODEL_Album));
|
||||
fragments.add(new MusicLibsFragment(this,MusicLibsAdapter.LIBS_MODEL_PLAY_Collection));
|
||||
fragments.add(new MusicLibsFragment(this,MusicLibsAdapter.LIBS_MODEL_Tmp));
|
||||
fragments = new ArrayList<>();
|
||||
fragments.add(new MusicLibsFragment(this, MusicLibsAdapter.LIBS_MODEL_ALL));
|
||||
fragments.add(new MusicLibsFragment(this, MusicLibsAdapter.LIBS_MODEL_Album));
|
||||
fragments.add(new MusicLibsFragment(this, MusicLibsAdapter.LIBS_MODEL_PLAY_Collection));
|
||||
fragments.add(new MusicLibsFragment(this, MusicLibsAdapter.LIBS_MODEL_Tmp));
|
||||
for (MusicLibsFragment fragment : fragments) {
|
||||
fragment.setPlayContainer(browserHelper);
|
||||
}
|
||||
@ -152,10 +154,10 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
fragments.get(tab.getPosition()).update();
|
||||
}
|
||||
});
|
||||
TabLayoutMediator mediator=new TabLayoutMediator(tabLayout, viewPager, true, new TabLayoutMediator.TabConfigurationStrategy() {
|
||||
TabLayoutMediator mediator = new TabLayoutMediator(tabLayout, viewPager, true, new TabLayoutMediator.TabConfigurationStrategy() {
|
||||
@Override
|
||||
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
||||
switch (position){
|
||||
switch (position) {
|
||||
case 0:
|
||||
tab.setText("全部");
|
||||
break;
|
||||
@ -176,11 +178,6 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
|
||||
private void setImage(Bitmap data) {
|
||||
Glide.with(this).load(data)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||
.into(album_image);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void setPlayData(final MusicData data) {
|
||||
@ -190,23 +187,13 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
artist.setText(data.getArtist());
|
||||
progressBar.setMax((int) (data.getDurationAsDouble() * 1000));
|
||||
progressBar.setProgress(bar_pos);
|
||||
data.getImg(AppData.minImageWidth,AppData.minImageHigh, new NetworkInterface() {
|
||||
@Override
|
||||
public void httpGetData(Object data, int state) {
|
||||
setImage((Bitmap) data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpError(Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
ImageLoader.getInstance(this).showImage(album_image, data.getImageUrl(), AppData.minImageWidth, AppData.minImageHigh, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
browserHelper.onStop();
|
||||
browserHelper.unPlayListener(playListener);
|
||||
browserHelper = null;
|
||||
finish();
|
||||
}
|
||||
@ -217,7 +204,7 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||
super.onPlaybackStateChanged(state);
|
||||
if (state.getState() == PlaybackStateCompat.STATE_PLAYING) {
|
||||
if (state.getState() == PlaybackStateCompat.STATE_PLAYING || browserHelper.isPlayer()) {
|
||||
progressBar.setProgress((int) (state.getPosition()));
|
||||
play.setImageResource(android.R.drawable.ic_media_pause);
|
||||
} else {
|
||||
@ -252,9 +239,5 @@ public class PlayLibsActivity extends AppCompatActivity {
|
||||
super.onQueueChanged(queue);
|
||||
System.out.println("不知道是啥变换了");
|
||||
}
|
||||
|
||||
public void setImage() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?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:id="@+id/layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:orientation="vertical">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -36,7 +38,8 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="120dp"
|
||||
@ -55,8 +58,7 @@
|
||||
android:shadowDy="5"
|
||||
android:shadowRadius="1"
|
||||
android:text="TextView"
|
||||
android:textColor="@color/colorBlack"
|
||||
/>
|
||||
android:textColor="@color/colorBlack" />
|
||||
|
||||
<cc.ibooker.ztextviewlib.MarqueeTextView
|
||||
android:id="@+id/artist"
|
||||
@ -70,8 +72,7 @@
|
||||
android:shadowRadius="1"
|
||||
android:text="TextView"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:textSize="10sp"
|
||||
/>
|
||||
android:textSize="10sp" />
|
||||
|
||||
<cc.ibooker.ztextviewlib.MarqueeTextView
|
||||
android:id="@+id/message"
|
||||
@ -85,8 +86,7 @@
|
||||
android:shadowRadius="1"
|
||||
android:text="TextView"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:textSize="8sp"
|
||||
/>
|
||||
android:textSize="8sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@ -95,7 +95,8 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="horizontal"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/dislike"
|
||||
@ -122,7 +123,15 @@
|
||||
android:scaleType="fitCenter"
|
||||
app:srcCompat="@drawable/ic_top" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1,13 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.4.10"
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
||||
classpath 'com.android.tools.build:gradle:7.3.1'
|
||||
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
|
||||
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -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.3.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
|
||||
|
Loading…
Reference in New Issue
Block a user