mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
Fix missing Replay Gain metadata from .m4a files (#396)
fix missing replay gain metadata from .m4a files
This commit is contained in:
parent
0fb6e55b12
commit
8b61396b0f
1 changed files with 16 additions and 9 deletions
|
|
@ -7,6 +7,7 @@ import androidx.media3.common.Metadata;
|
||||||
import androidx.media3.common.Tracks;
|
import androidx.media3.common.Tracks;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
|
import androidx.media3.extractor.metadata.id3.InternalFrame;
|
||||||
|
|
||||||
import com.cappielloantonio.tempo.model.ReplayGain;
|
import com.cappielloantonio.tempo.model.ReplayGain;
|
||||||
|
|
||||||
|
|
@ -82,26 +83,32 @@ public class ReplayGainUtil {
|
||||||
private static ReplayGain setReplayGains(Metadata.Entry entry) {
|
private static ReplayGain setReplayGains(Metadata.Entry entry) {
|
||||||
ReplayGain replayGain = new ReplayGain();
|
ReplayGain replayGain = new ReplayGain();
|
||||||
|
|
||||||
if (entry.toString().contains(tags[0])) {
|
// The logic below assumes .toString() contains the dB value. That's not the case for InternalFrame
|
||||||
replayGain.setTrackGain(parseReplayGainTag(entry));
|
String str = entry.toString();
|
||||||
|
if (entry instanceof InternalFrame) {
|
||||||
|
str = ((InternalFrame) entry).description + ((InternalFrame) entry).text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.toString().contains(tags[1])) {
|
if (str.contains(tags[0])) {
|
||||||
replayGain.setAlbumGain(parseReplayGainTag(entry));
|
replayGain.setTrackGain(parseReplayGainTag(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.toString().contains(tags[2])) {
|
if (str.contains(tags[1])) {
|
||||||
replayGain.setTrackGain(parseReplayGainTag(entry) / 256f);
|
replayGain.setAlbumGain(parseReplayGainTag(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.toString().contains(tags[3])) {
|
if (str.contains(tags[2])) {
|
||||||
replayGain.setAlbumGain(parseReplayGainTag(entry) / 256f);
|
replayGain.setTrackGain(parseReplayGainTag(str) / 256f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.contains(tags[3])) {
|
||||||
|
replayGain.setAlbumGain(parseReplayGainTag(str) / 256f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return replayGain;
|
return replayGain;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Float parseReplayGainTag(Metadata.Entry entry) {
|
private static Float parseReplayGainTag(String entry) {
|
||||||
try {
|
try {
|
||||||
return Float.parseFloat(entry.toString().replaceAll("[^\\d.-]", ""));
|
return Float.parseFloat(entry.toString().replaceAll("[^\\d.-]", ""));
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue