Bigger buffer

This commit is contained in:
exttex 2020-10-17 20:26:42 +02:00
parent ae319b9689
commit 0ef1be2084

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
@ -472,8 +473,9 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
uri = Uri.parse(((String)map.get("uri")).replace("#" + fragment, "")); uri = Uri.parse(((String)map.get("uri")).replace("#" + fragment, ""));
return new ProgressiveMediaSource.Factory( return new ProgressiveMediaSource.Factory(
() -> { () -> {
HttpDataSource deezerDataSource = new DeezerDataSource(fragment); return new DeezerDataSource(fragment);
return deezerDataSource; // HttpDataSource deezerDataSource = new DeezerDataSource(fragment);
// return deezerDataSource;
} }
).setTag(id).createMediaSource(uri); ).setTag(id).createMediaSource(uri);
} }
@ -565,7 +567,11 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
private void ensurePlayerInitialized() { private void ensurePlayerInitialized() {
if (player == null) { if (player == null) {
player = new SimpleExoPlayer.Builder(context).build(); //Load buffer
DefaultLoadControl.Builder loadControlBuilder = new DefaultLoadControl.Builder();
loadControlBuilder.setBufferDurationsMs(12500, 200000, 2500, 6000);
player = new SimpleExoPlayer.Builder(context).setLoadControl(loadControlBuilder.createDefaultLoadControl()).build();
player.addMetadataOutput(this); player.addMetadataOutput(this);
player.addListener(this); player.addListener(this);
player.addAudioListener(this); player.addAudioListener(this);
@ -595,11 +601,21 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
String qualityString = ""; String qualityString = "";
if (player != null && player.getAudioFormat() != null && player.getAudioFormat().sampleMimeType != null) { if (player != null && player.getAudioFormat() != null) {
if (player.getAudioFormat().sampleMimeType.equals("audio/mpeg")) { if (player.getAudioFormat().sampleMimeType != null) {
qualityString = "MP3"; if (player.getAudioFormat().sampleMimeType.equals("audio/mpeg")) {
qualityString = "MP3";
} else {
qualityString = "FLAC";
}
} else { } else {
qualityString = "FLAC"; if (player.getAudioFormat().containerMimeType != null) {
if (player.getAudioFormat().containerMimeType.equals("audio/mpeg")) {
qualityString = "MP3";
} else {
qualityString = "FLAC";
}
}
} }
} }
event.put("qualityString", qualityString); event.put("qualityString", qualityString);