mirror of
https://github.com/androidx/media.git
synced 2025-04-29 22:36:54 +08:00
Enable scrubbing for local files in the demo app
Scrubbing mode doesn't really work for assets loaded over the network. This also assumes `asset://`, `data://` and `android.resource://` URIs are 'local' but not `content://` - because these can be loaded by any arbitrary `ContentResolver` which may do higher latency/lower bandwidth remote loading. PiperOrigin-RevId: 751389438
This commit is contained in:
parent
49b57b8da3
commit
ae7d7dc7e8
@ -15,10 +15,12 @@
|
||||
*/
|
||||
package androidx.media3.demo.main;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@ -40,6 +42,7 @@ import androidx.media3.common.TrackSelectionParameters;
|
||||
import androidx.media3.common.Tracks;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.datasource.DataSchemeDataSource;
|
||||
import androidx.media3.datasource.DataSource;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.RenderersFactory;
|
||||
@ -502,6 +505,25 @@ public class PlayerActivity extends AppCompatActivity
|
||||
}
|
||||
lastSeenTracks = tracks;
|
||||
}
|
||||
|
||||
@OptIn(markerClass = UnstableApi.class) // For PlayerView.setTimeBarScrubbingEnabled
|
||||
@Override
|
||||
public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
|
||||
if (playerView == null) {
|
||||
return;
|
||||
}
|
||||
if (mediaItem == null) {
|
||||
playerView.setTimeBarScrubbingEnabled(false);
|
||||
return;
|
||||
}
|
||||
String uriScheme = mediaItem.localConfiguration.uri.getScheme();
|
||||
playerView.setTimeBarScrubbingEnabled(
|
||||
TextUtils.isEmpty(uriScheme)
|
||||
|| uriScheme.equals(ContentResolver.SCHEME_FILE)
|
||||
|| uriScheme.equals("asset")
|
||||
|| uriScheme.equals(DataSchemeDataSource.SCHEME_DATA)
|
||||
|| uriScheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE));
|
||||
}
|
||||
}
|
||||
|
||||
private class PlayerErrorMessageProvider implements ErrorMessageProvider<PlaybackException> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user