mirror of
https://github.com/androidx/media.git
synced 2025-05-03 21:57:46 +08:00
enable/disable media source correctly when added to playlist
PiperOrigin-RevId: 270007370
This commit is contained in:
parent
826fe3ac27
commit
a60265b106
@ -132,6 +132,11 @@ import java.util.Set;
|
|||||||
mediaSourceByUid.put(holder.uid, holder);
|
mediaSourceByUid.put(holder.uid, holder);
|
||||||
if (isPrepared) {
|
if (isPrepared) {
|
||||||
prepareChildSource(holder);
|
prepareChildSource(holder);
|
||||||
|
if (mediaSourceByMediaPeriod.isEmpty()) {
|
||||||
|
enabledMediaSourceHolders.add(holder);
|
||||||
|
} else {
|
||||||
|
disableChildSource(holder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,6 +272,7 @@ import java.util.Set;
|
|||||||
for (int i = 0; i < mediaSourceHolders.size(); i++) {
|
for (int i = 0; i < mediaSourceHolders.size(); i++) {
|
||||||
MediaSourceHolder mediaSourceHolder = mediaSourceHolders.get(i);
|
MediaSourceHolder mediaSourceHolder = mediaSourceHolders.get(i);
|
||||||
prepareChildSource(mediaSourceHolder);
|
prepareChildSource(mediaSourceHolder);
|
||||||
|
enabledMediaSourceHolders.add(mediaSourceHolder);
|
||||||
}
|
}
|
||||||
isPrepared = true;
|
isPrepared = true;
|
||||||
}
|
}
|
||||||
@ -357,15 +363,19 @@ import java.util.Set;
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
MediaSourceHolder holder = iterator.next();
|
MediaSourceHolder holder = iterator.next();
|
||||||
if (holder.activeMediaPeriodIds.isEmpty()) {
|
if (holder.activeMediaPeriodIds.isEmpty()) {
|
||||||
@Nullable MediaSourceAndListener disabledChild = childSources.get(holder);
|
disableChildSource(holder);
|
||||||
if (disabledChild != null) {
|
|
||||||
disabledChild.mediaSource.disable(disabledChild.caller);
|
|
||||||
}
|
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableChildSource(MediaSourceHolder holder) {
|
||||||
|
@Nullable MediaSourceAndListener disabledChild = childSources.get(holder);
|
||||||
|
if (disabledChild != null) {
|
||||||
|
disabledChild.mediaSource.disable(disabledChild.caller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removeMediaSourcesInternal(int fromIndex, int toIndex) {
|
private void removeMediaSourcesInternal(int fromIndex, int toIndex) {
|
||||||
for (int index = toIndex - 1; index >= fromIndex; index--) {
|
for (int index = toIndex - 1; index >= fromIndex; index--) {
|
||||||
MediaSourceHolder holder = mediaSourceHolders.remove(index);
|
MediaSourceHolder holder = mediaSourceHolders.remove(index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user