Bug fixes

This commit is contained in:
DrKLO 2018-08-27 15:13:23 +03:00
parent fe599cd519
commit 7e327c1e2c
2 changed files with 33 additions and 32 deletions

@ -1 +1 @@
Subproject commit 23ae67306d7fa1c4d5a8a9c8653f63ab93100f88 Subproject commit bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34

View file

@ -323,56 +323,57 @@ public class MusicPlayerService extends Service implements NotificationCenter.No
} }
if (remoteControlClient != null) { if (remoteControlClient != null) {
int currentID=MediaController.getInstance().getPlayingMessageObject().getId(); int currentID = MediaController.getInstance().getPlayingMessageObject().getId();
if(notificationMessageID!=currentID){ if (notificationMessageID != currentID) {
notificationMessageID=currentID; notificationMessageID = currentID;
RemoteControlClient.MetadataEditor metadataEditor=remoteControlClient.editMetadata(true); RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
if(audioInfo!=null && !TextUtils.isEmpty(audioInfo.getAlbum())) if (audioInfo != null && !TextUtils.isEmpty(audioInfo.getAlbum()))
metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, audioInfo.getAlbum()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, audioInfo.getAlbum());
metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration*1000L); metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration * 1000L);
if(audioInfo!=null && audioInfo.getCover()!=null){ if (audioInfo != null && audioInfo.getCover() != null) {
try{ try {
metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover());
}catch(Throwable e){ } catch (Throwable e) {
FileLog.e(e); FileLog.e(e);
} }
} }
metadataEditor.apply(); metadataEditor.apply();
AndroidUtilities.runOnUIThread(new Runnable(){ AndroidUtilities.runOnUIThread(new Runnable() {
@Override @Override
public void run(){ public void run() {
if(remoteControlClient==null) if (remoteControlClient == null || MediaController.getInstance().getPlayingMessageObject() == null) {
return; return;
if(MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration==C.TIME_UNSET){ }
if (MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration == C.TIME_UNSET) {
AndroidUtilities.runOnUIThread(this, 500); AndroidUtilities.runOnUIThread(this, 500);
return; return;
} }
RemoteControlClient.MetadataEditor metadataEditor=remoteControlClient.editMetadata(false); RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(false);
metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration*1000L); metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration * 1000L);
metadataEditor.apply(); metadataEditor.apply();
if(Build.VERSION.SDK_INT>=18){ if (Build.VERSION.SDK_INT >= 18) {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING, remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING,
Math.max(MediaController.getInstance().getPlayingMessageObject().audioProgressSec*1000L, 100), Math.max(MediaController.getInstance().getPlayingMessageObject().audioProgressSec * 1000L, 100),
MediaController.getInstance().isMessagePaused() ? 0f : 1f); MediaController.getInstance().isMessagePaused() ? 0f : 1f);
}else{ } else {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING); remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING);
} }
} }
}, 1000); }, 1000);
} }
if(MediaController.getInstance().isDownloadingCurrentMessage()){ if (MediaController.getInstance().isDownloadingCurrentMessage()) {
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING); remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);
}else{ } else {
RemoteControlClient.MetadataEditor metadataEditor=remoteControlClient.editMetadata(false); RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(false);
metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration*1000L); metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration * 1000L);
metadataEditor.apply(); metadataEditor.apply();
if(Build.VERSION.SDK_INT>=18){ if (Build.VERSION.SDK_INT >= 18) {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING, remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING,
Math.max(MediaController.getInstance().getPlayingMessageObject().audioProgressSec*1000L, 100), Math.max(MediaController.getInstance().getPlayingMessageObject().audioProgressSec * 1000L, 100),
MediaController.getInstance().isMessagePaused() ? 0f : 1f); MediaController.getInstance().isMessagePaused() ? 0f : 1f);
}else{ } else {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING); remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING);
} }
} }
@ -420,10 +421,10 @@ public class MusicPlayerService extends Service implements NotificationCenter.No
} else { } else {
stopSelf(); stopSelf();
} }
}else if(id==NotificationCenter.messagePlayingDidSeek){ } else if (id == NotificationCenter.messagePlayingDidSeek) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if(remoteControlClient!=null && Build.VERSION.SDK_INT>=18){ if (remoteControlClient != null && Build.VERSION.SDK_INT >= 18) {
long progress=Math.round(messageObject.audioPlayerDuration*(float)args[1])*1000L; long progress = Math.round(messageObject.audioPlayerDuration * (float) args[1]) * 1000L;
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING, remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING,
progress, progress,
MediaController.getInstance().isMessagePaused() ? 0f : 1f); MediaController.getInstance().isMessagePaused() ? 0f : 1f);