fix:添加到列表播放时通知栏没更新
This commit is contained in:
parent
3aef3c1504
commit
578f756635
@ -378,7 +378,7 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
public void bind(MusicData data) {
|
public void bind(MusicData data) {
|
||||||
title.setText(data.getTitle());
|
title.setText(data.getTitle());
|
||||||
artist.setText(data.getArtist());
|
artist.setText(data.getArtist());
|
||||||
icon.setImageResource(R.drawable.ic_dir);
|
//icon.setImageResource(R.drawable.ic_dir);
|
||||||
collection.setVisibility(View.VISIBLE);
|
collection.setVisibility(View.VISIBLE);
|
||||||
if (!data.isDir()) {
|
if (!data.isDir()) {
|
||||||
message.setText(data.getBitRate() + "kbps | " + data.getSampleRate() + "hz | " + data.getEncodingType());
|
message.setText(data.getBitRate() + "kbps | " + data.getSampleRate() + "hz | " + data.getEncodingType());
|
||||||
@ -476,6 +476,9 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
@Override
|
@Override
|
||||||
public void httpGetData(Object data, int state) {
|
public void httpGetData(Object data, int state) {
|
||||||
Glide.with(MyApplication.application).load((Bitmap) data)
|
Glide.with(MyApplication.application).load((Bitmap) data)
|
||||||
|
.placeholder(holder.icon.getDrawable())
|
||||||
|
.dontAnimate()
|
||||||
|
.skipMemoryCache(false)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||||
.into(holder.icon);
|
.into(holder.icon);
|
||||||
}
|
}
|
||||||
@ -519,7 +522,8 @@ public class MusicLibsAdapter extends RecyclerView.Adapter<MusicLibsAdapter.View
|
|||||||
AppTools.toast(i + "首歌已添加到队列中");
|
AppTools.toast(i + "首歌已添加到队列中");
|
||||||
popupWindow.dismiss();
|
popupWindow.dismiss();
|
||||||
MusicContainer.getInstance().setPlayModel(MusicContainer.PLAY_MODEL_ORDER);
|
MusicContainer.getInstance().setPlayModel(MusicContainer.PLAY_MODEL_ORDER);
|
||||||
MusicContainer.getInstance().playNext();
|
browserHelper.getTransportControls().play();
|
||||||
|
browserHelper.getTransportControls().skipToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,10 +28,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MusicService extends MediaBrowserServiceCompat {
|
public class MusicService extends MediaBrowserServiceCompat {
|
||||||
|
private final static String TAG="MusicService";
|
||||||
public MediaSessionCompat mediaSession;
|
public MediaSessionCompat mediaSession;
|
||||||
private PlaybackStateCompat.Builder stateBuilder;
|
private PlaybackStateCompat.Builder stateBuilder;
|
||||||
private MediaNotificationManager notificationManager;
|
private MediaNotificationManager notificationManager;
|
||||||
private int mState = PlaybackStateCompat.STATE_PLAYING;
|
private int mState = PlaybackStateCompat.STATE_PLAYING;
|
||||||
|
private String playMd5="";
|
||||||
|
|
||||||
private static final long MEDIA_SESSION_ACTIONS = PlaybackStateCompat.ACTION_PLAY
|
private static final long MEDIA_SESSION_ACTIONS = PlaybackStateCompat.ACTION_PLAY
|
||||||
| PlaybackStateCompat.ACTION_PAUSE
|
| PlaybackStateCompat.ACTION_PAUSE
|
||||||
@ -61,12 +63,19 @@ public class MusicService extends MediaBrowserServiceCompat {
|
|||||||
MusicContainer.getInstance().addCompletionListener(new PlayCompletionListener());
|
MusicContainer.getInstance().addCompletionListener(new PlayCompletionListener());
|
||||||
MediaBrowserHelper helper = new MediaBrowserHelper(this);
|
MediaBrowserHelper helper = new MediaBrowserHelper(this);
|
||||||
helper.regPlayListener(new MediaControllerCompat.Callback() {
|
helper.regPlayListener(new MediaControllerCompat.Callback() {
|
||||||
|
private String compat_md5="";
|
||||||
|
private MediaMetadataCompat compat;
|
||||||
@Override
|
@Override
|
||||||
public void onMetadataChanged(MediaMetadataCompat metadata) {
|
public void onMetadataChanged(MediaMetadataCompat metadata) {
|
||||||
super.onMetadataChanged(metadata);
|
super.onMetadataChanged(metadata);
|
||||||
if(metadata==null){
|
if(metadata==null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String md5=metadata.getString("md5");
|
||||||
|
if(compat_md5.equals(md5)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
compat_md5=md5;
|
||||||
Notification notification = notificationManager.getNotification(metadata, builderState(0).build(), getSessionToken());
|
Notification notification = notificationManager.getNotification(metadata, builderState(0).build(), getSessionToken());
|
||||||
notificationManager.getManager()
|
notificationManager.getManager()
|
||||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||||
@ -107,7 +116,12 @@ public class MusicService extends MediaBrowserServiceCompat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void seekToNotification(long pos) {
|
public void seekToNotification(long pos) {
|
||||||
|
MusicData data = MusicContainer.getInstance().getNowPlayData();
|
||||||
|
if(!playMd5.equals(data.getMd5())){
|
||||||
|
playMd5=data.getMd5();
|
||||||
|
mediaSession.setMetadata(MusicContainer.getInstance().getNowPlayMetadataCompat());
|
||||||
|
updateNotification();
|
||||||
|
}
|
||||||
mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
|
mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
|
||||||
.setActions(MEDIA_SESSION_ACTIONS)
|
.setActions(MEDIA_SESSION_ACTIONS)
|
||||||
.setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build());
|
.setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build());
|
||||||
@ -155,7 +169,7 @@ public class MusicService extends MediaBrowserServiceCompat {
|
|||||||
|
|
||||||
MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat();
|
MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat();
|
||||||
System.out.println("更新通知栏:" + metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID));
|
System.out.println("更新通知栏:" + metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID));
|
||||||
mediaSession.setMetadata(metadataCompat);
|
//mediaSession.setMetadata(metadataCompat);
|
||||||
mediaSession.setActive(true);
|
mediaSession.setActive(true);
|
||||||
Notification notification =
|
Notification notification =
|
||||||
notificationManager.getNotification(
|
notificationManager.getNotification(
|
||||||
@ -166,10 +180,7 @@ public class MusicService extends MediaBrowserServiceCompat {
|
|||||||
|
|
||||||
public class MediaSessionCallback extends MediaSessionCompat.Callback {
|
public class MediaSessionCallback extends MediaSessionCompat.Callback {
|
||||||
MusicReceiver receiver = new MusicReceiver();
|
MusicReceiver receiver = new MusicReceiver();
|
||||||
;
|
|
||||||
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlay() {
|
public void onPlay() {
|
||||||
@ -191,6 +202,7 @@ public class MusicService extends MediaBrowserServiceCompat {
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
mState = PlaybackStateCompat.STATE_PAUSED;
|
mState = PlaybackStateCompat.STATE_PAUSED;
|
||||||
MusicContainer.getInstance().pause();
|
MusicContainer.getInstance().pause();
|
||||||
|
|
||||||
//MusicService.this.onSeekTo(-1);
|
//MusicService.this.onSeekTo(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,8 +322,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||||
super.onPlaybackStateChanged(state);
|
super.onPlaybackStateChanged(state);
|
||||||
//System.out.println("播放状态变化:" + state.getPosition() + " " + seekBar.getMax());
|
//System.out.println("[MainActivity]播放状态变化:" + state.getPosition() + " " + seekBar.getMax()+" state.getState() = "+state.getState()+" isPlay = "+browserHelper.isPlayer());
|
||||||
if (state.getState() == PlaybackStateCompat.STATE_PLAYING) {
|
if (state.getState() == PlaybackStateCompat.STATE_PLAYING || browserHelper.isPlayer()) {
|
||||||
int duration = (int) (state.getPosition() / 1000);
|
int duration = (int) (state.getPosition() / 1000);
|
||||||
int minutes = duration / 60;
|
int minutes = duration / 60;
|
||||||
int seconds = duration % 60;
|
int seconds = duration % 60;
|
||||||
@ -343,7 +343,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
super.onMetadataChanged(metadata);
|
super.onMetadataChanged(metadata);
|
||||||
String md5 = null;
|
String md5 = null;
|
||||||
try {
|
try {
|
||||||
System.out.println("播放歌曲变换:" + metadata.getString("md5"));
|
System.out.println("[MainActivity]播放歌曲变换:" + metadata.getString("md5"));
|
||||||
md5 = metadata.getString("md5");
|
md5 = metadata.getString("md5");
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
@ -178,6 +178,7 @@ public class PlayLibsActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void setImage(Bitmap data) {
|
private void setImage(Bitmap data) {
|
||||||
Glide.with(this).load(data)
|
Glide.with(this).load(data)
|
||||||
|
.placeholder(album_image.getDrawable())
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
|
||||||
.into(album_image);
|
.into(album_image);
|
||||||
}
|
}
|
||||||
@ -217,7 +218,7 @@ public class PlayLibsActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||||
super.onPlaybackStateChanged(state);
|
super.onPlaybackStateChanged(state);
|
||||||
if (state.getState() == PlaybackStateCompat.STATE_PLAYING) {
|
if (state.getState() == PlaybackStateCompat.STATE_PLAYING || browserHelper.isPlayer()) {
|
||||||
progressBar.setProgress((int) (state.getPosition()));
|
progressBar.setProgress((int) (state.getPosition()));
|
||||||
play.setImageResource(android.R.drawable.ic_media_pause);
|
play.setImageResource(android.R.drawable.ic_media_pause);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:clipChildren="false"
|
||||||
android:descendantFocusability="blocksDescendants"
|
android:descendantFocusability="blocksDescendants"
|
||||||
android:orientation="vertical">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -36,7 +38,8 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="120dp"
|
android:layout_width="120dp"
|
||||||
@ -55,8 +58,7 @@
|
|||||||
android:shadowDy="5"
|
android:shadowDy="5"
|
||||||
android:shadowRadius="1"
|
android:shadowRadius="1"
|
||||||
android:text="TextView"
|
android:text="TextView"
|
||||||
android:textColor="@color/colorBlack"
|
android:textColor="@color/colorBlack" />
|
||||||
/>
|
|
||||||
|
|
||||||
<cc.ibooker.ztextviewlib.MarqueeTextView
|
<cc.ibooker.ztextviewlib.MarqueeTextView
|
||||||
android:id="@+id/artist"
|
android:id="@+id/artist"
|
||||||
@ -70,8 +72,7 @@
|
|||||||
android:shadowRadius="1"
|
android:shadowRadius="1"
|
||||||
android:text="TextView"
|
android:text="TextView"
|
||||||
android:textColor="@color/colorBlack"
|
android:textColor="@color/colorBlack"
|
||||||
android:textSize="10sp"
|
android:textSize="10sp" />
|
||||||
/>
|
|
||||||
|
|
||||||
<cc.ibooker.ztextviewlib.MarqueeTextView
|
<cc.ibooker.ztextviewlib.MarqueeTextView
|
||||||
android:id="@+id/message"
|
android:id="@+id/message"
|
||||||
@ -85,8 +86,7 @@
|
|||||||
android:shadowRadius="1"
|
android:shadowRadius="1"
|
||||||
android:text="TextView"
|
android:text="TextView"
|
||||||
android:textColor="@color/colorBlack"
|
android:textColor="@color/colorBlack"
|
||||||
android:textSize="8sp"
|
android:textSize="8sp" />
|
||||||
/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@ -95,7 +95,8 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:gravity="end"
|
android:gravity="end"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/dislike"
|
android:id="@+id/dislike"
|
||||||
@ -122,7 +123,15 @@
|
|||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
app:srcCompat="@drawable/ic_top" />
|
app:srcCompat="@drawable/ic_top" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="Button" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
classpath 'com.android.tools.build:gradle:7.2.1'
|
||||||
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user