修复图片无法载入问题
修复通知栏一直弹的问题
This commit is contained in:
parent
20b80d380a
commit
17272ec4d3
@ -276,9 +276,9 @@ public class MusicData {
|
||||
isDownloadImg = true;
|
||||
JSONObject json = new JSONObject();
|
||||
if (StringUtil.isEmpty(getAlbum())) {
|
||||
json.put("fileName", getFile());
|
||||
json.put("fileName", getMd5());
|
||||
} else {
|
||||
json.put("fileName", AppTools.getUrlBase64(getAlbum()));
|
||||
json.put("fileName", getMd5());
|
||||
json.put("type", "album");
|
||||
}
|
||||
System.out.println("下载图片:" + HttpManager.NetworkAPI.MUSIC_IMAGE + "?" + NetworkTool.toGetSplice(json));
|
||||
|
@ -10,6 +10,7 @@ import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v4.media.MediaBrowserCompat;
|
||||
import android.support.v4.media.MediaMetadataCompat;
|
||||
import android.support.v4.media.session.MediaControllerCompat;
|
||||
import android.support.v4.media.session.MediaSessionCompat;
|
||||
import android.support.v4.media.session.PlaybackStateCompat;
|
||||
|
||||
@ -17,6 +18,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media.MediaBrowserServiceCompat;
|
||||
|
||||
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
|
||||
import com.yutou.nas_music_player.containers.MediaNotificationManager;
|
||||
import com.yutou.nas_music_player.containers.MusicContainer;
|
||||
import com.yutou.nas_music_player.Datas.MusicData;
|
||||
@ -52,11 +54,24 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
.setActions(MEDIA_SESSION_ACTIONS);
|
||||
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);
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, 233, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
mediaSession.setSessionActivity(pi);
|
||||
setSessionToken(mediaSession.getSessionToken());
|
||||
MusicContainer.getInstance().addCompletionListener(new PlayCompletionListener());
|
||||
MediaBrowserHelper helper = new MediaBrowserHelper(this);
|
||||
helper.regPlayListener(new MediaControllerCompat.Callback() {
|
||||
@Override
|
||||
public void onMetadataChanged(MediaMetadataCompat metadata) {
|
||||
super.onMetadataChanged(metadata);
|
||||
if(metadata==null){
|
||||
return;
|
||||
}
|
||||
Notification notification = notificationManager.getNotification(metadata, builderState(0).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -78,11 +93,7 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
}
|
||||
|
||||
public void seekToNotification(long pos) {
|
||||
MusicData data = MusicContainer.getInstance().getNowPlayData();
|
||||
MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getMetadataCompat(data);
|
||||
Notification notification = notificationManager.getNotification(metadataCompat, builderState(pos).build(), getSessionToken());
|
||||
notificationManager.getManager()
|
||||
.notify(MediaNotificationManager.NOTIFICATION_ID, notification);
|
||||
|
||||
mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
|
||||
.setActions(MEDIA_SESSION_ACTIONS)
|
||||
.setState(mState, pos, 1.0f, SystemClock.elapsedRealtime()).build());
|
||||
@ -125,10 +136,11 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void updateNotification() {
|
||||
|
||||
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.setActive(true);
|
||||
Notification notification =
|
||||
@ -137,10 +149,12 @@ public class MusicService extends MediaBrowserServiceCompat {
|
||||
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);;
|
||||
|
||||
public class MediaSessionCallback extends MediaSessionCompat.Callback {
|
||||
MusicReceiver receiver = new MusicReceiver();
|
||||
;
|
||||
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
||||
;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.1.1'
|
||||
classpath 'com.android.tools.build:gradle:7.1.3'
|
||||
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user