Do not send new audio metadata to device if nothing has changed
This prevents some players which send a metadata changed intent every second to drain the battery
This commit is contained in:
parent
8d3bd494b4
commit
d1a62968f6
|
@ -3,7 +3,6 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -13,20 +12,20 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
|||
|
||||
public class MusicPlaybackReceiver extends BroadcastReceiver {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MusicPlaybackReceiver.class);
|
||||
private static MusicSpec lastMusicSpec = new MusicSpec();
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String artist = intent.getStringExtra("artist");
|
||||
String album = intent.getStringExtra("album");
|
||||
String track = intent.getStringExtra("track");
|
||||
|
||||
LOG.info("Current track: " + artist + ", " + album + ", " + track);
|
||||
|
||||
MusicSpec musicSpec = new MusicSpec();
|
||||
musicSpec.artist = artist;
|
||||
musicSpec.album = album;
|
||||
musicSpec.track = track;
|
||||
|
||||
GBApplication.deviceService().onSetMusicInfo(musicSpec);
|
||||
musicSpec.artist = intent.getStringExtra("artist");
|
||||
musicSpec.album = intent.getStringExtra("album");
|
||||
musicSpec.track = intent.getStringExtra("track");
|
||||
if (!lastMusicSpec.equals(musicSpec)) {
|
||||
lastMusicSpec = musicSpec;
|
||||
LOG.info("Update Music Info: " + musicSpec.artist + " / " + musicSpec.album + " / " + musicSpec.track);
|
||||
GBApplication.deviceService().onSetMusicInfo(musicSpec);
|
||||
} else {
|
||||
LOG.info("got metadata changed intent, but nothing changed, ignoring.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,29 @@ public class MusicSpec {
|
|||
public static final int MUSIC_NEXT = 4;
|
||||
public static final int MUSIC_PREVIOUS = 5;
|
||||
|
||||
public String artist;
|
||||
public String album;
|
||||
public String track;
|
||||
public String artist = "";
|
||||
public String album = "";
|
||||
public String track = "";
|
||||
public int duration;
|
||||
public int trackCount;
|
||||
public int trackNr;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof MusicSpec)) {
|
||||
return false;
|
||||
}
|
||||
MusicSpec musicSpec = (MusicSpec) obj;
|
||||
|
||||
return this.artist.equals(musicSpec.artist) &&
|
||||
this.album.equals(musicSpec.album) &&
|
||||
this.track.equals(musicSpec.track) &&
|
||||
this.duration == musicSpec.duration &&
|
||||
this.trackCount == musicSpec.trackCount &&
|
||||
this.trackNr == musicSpec.trackNr;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue