update
This commit is contained in:
parent
7704be296d
commit
4daa74c16b
@ -36,7 +36,6 @@ dependencies {
|
|||||||
implementation 'com.alibaba:fastjson:1.1.72.android'
|
implementation 'com.alibaba:fastjson:1.1.72.android'
|
||||||
//noinspection GradleCompatible
|
//noinspection GradleCompatible
|
||||||
implementation 'com.android.support:support-media-compat:28.0.0'
|
implementation 'com.android.support:support-media-compat:28.0.0'
|
||||||
|
implementation 'androidx.palette:palette:1.0.0'
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -19,8 +19,12 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".views.MainActivity" />
|
<activity android:name=".views.MainActivity"
|
||||||
<service android:name=".services.MusicService">
|
android:theme="@style/Theme.AppCompat.NoActionBar"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
/>
|
||||||
|
<service android:name=".services.MusicService"
|
||||||
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.media.browse.MediaBrowserService" />
|
<action android:name="android.media.browse.MediaBrowserService" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
@ -3,6 +3,7 @@ package com.yutou.nas_music_player.containers;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@ -10,6 +11,8 @@ import com.yutou.nas_music_player.Interfaces.NetworkInterface;
|
|||||||
import com.yutou.nas_music_player.tools.NetworkTool;
|
import com.yutou.nas_music_player.tools.NetworkTool;
|
||||||
import com.yutou.nas_music_player.tools.StringUtil;
|
import com.yutou.nas_music_player.tools.StringUtil;
|
||||||
|
|
||||||
|
import androidx.palette.graphics.Palette;
|
||||||
|
|
||||||
public class MusicData {
|
public class MusicData {
|
||||||
private String artist;//艺术家
|
private String artist;//艺术家
|
||||||
private String album;//专辑
|
private String album;//专辑
|
||||||
@ -172,4 +175,10 @@ public class MusicData {
|
|||||||
});
|
});
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
public int getImageColor(){
|
||||||
|
if(img==null){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return Palette.from(img).generate().getLightVibrantColor(Color.parseColor("#6DE1A1"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ package com.yutou.nas_music_player.views;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.media.MediaMetadataCompat;
|
import android.support.v4.media.MediaMetadataCompat;
|
||||||
import android.support.v4.media.session.MediaControllerCompat;
|
import android.support.v4.media.session.MediaControllerCompat;
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
import android.support.v4.media.session.MediaSessionCompat;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.MediaController;
|
import android.widget.MediaController;
|
||||||
@ -15,6 +17,7 @@ import android.widget.MediaController;
|
|||||||
import com.yutou.nas_music_player.R;
|
import com.yutou.nas_music_player.R;
|
||||||
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
|
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
|
||||||
import com.yutou.nas_music_player.containers.MusicContainer;
|
import com.yutou.nas_music_player.containers.MusicContainer;
|
||||||
|
import com.yutou.nas_music_player.containers.MusicData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -26,6 +29,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setBarColor(android.R.color.transparent);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
MusicContainer.getInstance();
|
MusicContainer.getInstance();
|
||||||
play = findViewById(R.id.play);
|
play = findViewById(R.id.play);
|
||||||
@ -47,13 +51,20 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
previous.setOnClickListener(new View.OnClickListener() {
|
previous.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
MusicData data=MusicContainer.getInstance().getNowPlayData();
|
||||||
|
if(data!=null){
|
||||||
|
setBarColor(data.getImageColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
browserHelper = new MediaBrowserHelper(this);
|
browserHelper = new MediaBrowserHelper(this);
|
||||||
browserHelper.regPlayListener(new PlayListener());
|
browserHelper.regPlayListener(new PlayListener());
|
||||||
}
|
}
|
||||||
|
public void setBarColor(int color){
|
||||||
|
getWindow().setStatusBarColor(color);
|
||||||
|
getWindow().setNavigationBarColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
private class PlayListener extends MediaControllerCompat.Callback {
|
private class PlayListener extends MediaControllerCompat.Callback {
|
||||||
@Override
|
@Override
|
||||||
@ -78,5 +89,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void onQueueChanged(List<MediaSessionCompat.QueueItem> queue) {
|
public void onQueueChanged(List<MediaSessionCompat.QueueItem> queue) {
|
||||||
super.onQueueChanged(queue);
|
super.onQueueChanged(queue);
|
||||||
}
|
}
|
||||||
|
public void setImage(){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,8 @@
|
|||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/frameLayout"
|
android:id="@+id/frameLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="500dp"
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
@ -21,68 +22,141 @@
|
|||||||
android:scaleType="fitXY"
|
android:scaleType="fitXY"
|
||||||
android:src="@drawable/ic_launcher_background" />
|
android:src="@drawable/ic_launcher_background" />
|
||||||
|
|
||||||
<ImageView
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/imageView2"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="200dp"
|
android:layout_height="match_parent">
|
||||||
android:layout_height="200dp"
|
|
||||||
android:layout_gravity="center"
|
<ImageView
|
||||||
android:src="@drawable/ic_launcher_foreground" />
|
android:id="@+id/imageView2"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="150dp"
|
||||||
|
android:src="@drawable/ic_launcher_foreground"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="32dp"
|
||||||
|
android:layout_marginEnd="32dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:progressTint="#FF1313"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/positionTime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="00:00"
|
||||||
|
android:textColor="@color/colorBlack" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/durationTime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="end"
|
||||||
|
android:text="00:00"
|
||||||
|
android:textColor="@color/colorBlack" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="#000E0A0A"
|
||||||
|
android:backgroundTint="#D12828"
|
||||||
|
android:elevation="6dp"
|
||||||
|
android:max="100"
|
||||||
|
android:progress="50"
|
||||||
|
android:progressBackgroundTintMode="add"
|
||||||
|
android:progressTint="#EC1E1E"
|
||||||
|
android:textColor="@color/colorBlack" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
|
||||||
|
android:id="@+id/linearLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/previous"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginEnd="30dp"
|
||||||
|
android:src="@android:drawable/ic_media_previous" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/play"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@android:drawable/ic_media_play" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/next"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginStart="30dp"
|
||||||
|
android:src="@android:drawable/ic_media_next" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/linearLayout2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:elevation="4dp"
|
||||||
|
android:text="title"
|
||||||
|
android:shadowColor="@color/textColorGray"
|
||||||
|
android:shadowRadius="1"
|
||||||
|
android:shadowDx="5"
|
||||||
|
android:shadowDy="5"
|
||||||
|
android:textColor="@color/musicTitle"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/artist"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="artist-album"
|
||||||
|
android:textColor="@color/musicArtist"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/linearLayout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_marginTop="20dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/frameLayout">
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/previous"
|
|
||||||
android:layout_width="60dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginEnd="30dp"
|
|
||||||
android:src="@android:drawable/ic_media_previous" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/play"
|
|
||||||
android:layout_width="60dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:src="@android:drawable/ic_media_play" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/next"
|
|
||||||
android:layout_width="60dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginStart="30dp"
|
|
||||||
android:src="@android:drawable/ic_media_next" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:orientation="vertical"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/linearLayout">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="title" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/artist"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="artist-album" />
|
|
||||||
</LinearLayout>
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -3,4 +3,9 @@
|
|||||||
<color name="colorPrimary">#6200EE</color>
|
<color name="colorPrimary">#6200EE</color>
|
||||||
<color name="colorPrimaryDark">#3700B3</color>
|
<color name="colorPrimaryDark">#3700B3</color>
|
||||||
<color name="colorAccent">#03DAC5</color>
|
<color name="colorAccent">#03DAC5</color>
|
||||||
|
<color name="colorBlack">#000000</color>
|
||||||
|
|
||||||
|
<color name="musicTitle">#000000</color>
|
||||||
|
<color name="musicArtist">#000000</color>
|
||||||
|
<color name="textColorGray">#DEDEDE</color>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user