fix incorrect songs during playback
This commit is contained in:
parent
853ecec314
commit
61267b705f
1 changed files with 20 additions and 8 deletions
|
|
@ -116,7 +116,7 @@ public class MultiPlayer implements Playback {
|
||||||
// queue and other information is currently handled outside exoplayer
|
// queue and other information is currently handled outside exoplayer
|
||||||
exoPlayer.setRepeatMode(Player.REPEAT_MODE_OFF);
|
exoPlayer.setRepeatMode(Player.REPEAT_MODE_OFF);
|
||||||
|
|
||||||
appendDataSource(path, true);
|
appendDataSource(path, 0);
|
||||||
isReady = true;
|
isReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,14 +126,16 @@ public class MultiPlayer implements Playback {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mediaSource.getSize() >= 2) {
|
if (mediaSource.getSize() == 2 && mediaSource.getMediaSource(1).getTag() != path) {
|
||||||
mediaSource.removeMediaSource(1);
|
mediaSource.removeMediaSource(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendDataSource(path, false);
|
if (mediaSource.getSize() != 2) {
|
||||||
|
appendDataSource(path, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendDataSource(String path, boolean next) {
|
private void appendDataSource(String path, int position) {
|
||||||
Uri uri = Uri.parse(path);
|
Uri uri = Uri.parse(path);
|
||||||
|
|
||||||
DataSource.Factory dataSource = new DefaultHttpDataSourceFactory(Util.getUserAgent(context, this.getClass().getName()));
|
DataSource.Factory dataSource = new DefaultHttpDataSourceFactory(Util.getUserAgent(context, this.getClass().getName()));
|
||||||
|
|
@ -148,13 +150,23 @@ public class MultiPlayer implements Playback {
|
||||||
public void onResponse(Call call, Response response) {
|
public void onResponse(Call call, Response response) {
|
||||||
MediaSource source;
|
MediaSource source;
|
||||||
if (response.header("Content-Type").equals("application/x-mpegURL")) {
|
if (response.header("Content-Type").equals("application/x-mpegURL")) {
|
||||||
source = new HlsMediaSource.Factory(dataSource).createMediaSource(uri);
|
source = new HlsMediaSource.Factory(dataSource)
|
||||||
|
.setTag(path)
|
||||||
|
.setAllowChunklessPreparation(true)
|
||||||
|
.createMediaSource(uri);
|
||||||
} else {
|
} else {
|
||||||
source = new ProgressiveMediaSource.Factory(dataSource).createMediaSource(uri);
|
source = new ProgressiveMediaSource.Factory(dataSource)
|
||||||
|
.setTag(path)
|
||||||
|
.createMediaSource(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaSource.addMediaSource(source);
|
if (mediaSource.getSize() < position) {
|
||||||
if (next) start();
|
mediaSource.addMediaSource(mediaSource.getSize(), source);
|
||||||
|
} else {
|
||||||
|
mediaSource.addMediaSource(position, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position == 0) start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue