Skip to content

Commit ed5b700

Browse files
toniheicopybara-github
authored andcommitted
Replace or suppress deprecated usages
Many usages are needed to support other deprecations and some can be replaced by the recommended direct alternative. Also replace links to deprecated/redirected dev site PiperOrigin-RevId: 601795998
1 parent 7424cff commit ed5b700

File tree

75 files changed

+400
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+400
-199
lines changed

demos/cast/src/main/java/androidx/media3/demo/cast/MainActivity.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.android.gms.cast.framework.CastButtonFactory;
4545
import com.google.android.gms.cast.framework.CastContext;
4646
import com.google.android.gms.dynamite.DynamiteModule;
47+
import com.google.common.util.concurrent.MoreExecutors;
4748

4849
/**
4950
* An activity that plays video using {@link ExoPlayer} and supports casting using ExoPlayer's Cast
@@ -65,7 +66,7 @@ public void onCreate(Bundle savedInstanceState) {
6566
super.onCreate(savedInstanceState);
6667
// Getting the cast context later than onStart can cause device discovery not to take place.
6768
try {
68-
castContext = CastContext.getSharedInstance(this);
69+
castContext = CastContext.getSharedInstance(this, MoreExecutors.directExecutor()).getResult();
6970
} catch (RuntimeException e) {
7071
Throwable cause = e.getCause();
7172
while (cause != null) {

demos/main/src/main/java/androidx/media3/demo/main/DownloadTracker.java

+42-26
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import android.content.Context;
2121
import android.content.DialogInterface;
2222
import android.net.Uri;
23-
import android.os.AsyncTask;
23+
import android.os.Handler;
24+
import android.os.Looper;
2425
import android.widget.Toast;
2526
import androidx.annotation.Nullable;
2627
import androidx.annotation.OptIn;
@@ -54,6 +55,9 @@
5455
import java.util.HashMap;
5556
import java.util.UUID;
5657
import java.util.concurrent.CopyOnWriteArraySet;
58+
import java.util.concurrent.ExecutorService;
59+
import java.util.concurrent.Executors;
60+
import java.util.concurrent.Future;
5761

5862
/** Tracks media that has been downloaded. */
5963
@OptIn(markerClass = androidx.media3.common.util.UnstableApi.class)
@@ -182,7 +186,7 @@ public void release() {
182186
trackSelectionDialog.dismiss();
183187
}
184188
if (widevineOfflineLicenseFetchTask != null) {
185-
widevineOfflineLicenseFetchTask.cancel(false);
189+
widevineOfflineLicenseFetchTask.cancel();
186190
}
187191
}
188192

@@ -358,14 +362,16 @@ private DownloadRequest buildDownloadRequest() {
358362

359363
/** Downloads a Widevine offline license in a background thread. */
360364
@RequiresApi(18)
361-
private static final class WidevineOfflineLicenseFetchTask extends AsyncTask<Void, Void, Void> {
365+
private static final class WidevineOfflineLicenseFetchTask {
362366

363367
private final Format format;
364368
private final MediaItem.DrmConfiguration drmConfiguration;
365369
private final DataSource.Factory dataSourceFactory;
366370
private final StartDownloadDialogHelper dialogHelper;
367371
private final DownloadHelper downloadHelper;
372+
private final ExecutorService executorService;
368373

374+
@Nullable Future<?> future;
369375
@Nullable private byte[] keySetId;
370376
@Nullable private DrmSession.DrmSessionException drmSessionException;
371377

@@ -375,39 +381,49 @@ public WidevineOfflineLicenseFetchTask(
375381
DataSource.Factory dataSourceFactory,
376382
StartDownloadDialogHelper dialogHelper,
377383
DownloadHelper downloadHelper) {
384+
this.executorService = Executors.newSingleThreadExecutor();
378385
this.format = format;
379386
this.drmConfiguration = drmConfiguration;
380387
this.dataSourceFactory = dataSourceFactory;
381388
this.dialogHelper = dialogHelper;
382389
this.downloadHelper = downloadHelper;
383390
}
384391

385-
@Override
386-
protected Void doInBackground(Void... voids) {
387-
OfflineLicenseHelper offlineLicenseHelper =
388-
OfflineLicenseHelper.newWidevineInstance(
389-
drmConfiguration.licenseUri.toString(),
390-
drmConfiguration.forceDefaultLicenseUri,
391-
dataSourceFactory,
392-
drmConfiguration.licenseRequestHeaders,
393-
new DrmSessionEventListener.EventDispatcher());
394-
try {
395-
keySetId = offlineLicenseHelper.downloadLicense(format);
396-
} catch (DrmSession.DrmSessionException e) {
397-
drmSessionException = e;
398-
} finally {
399-
offlineLicenseHelper.release();
392+
public void cancel() {
393+
if (future != null) {
394+
future.cancel(/* mayInterruptIfRunning= */ false);
400395
}
401-
return null;
402396
}
403397

404-
@Override
405-
protected void onPostExecute(Void aVoid) {
406-
if (drmSessionException != null) {
407-
dialogHelper.onOfflineLicenseFetchedError(drmSessionException);
408-
} else {
409-
dialogHelper.onOfflineLicenseFetched(downloadHelper, checkNotNull(keySetId));
410-
}
398+
public void execute() {
399+
future =
400+
executorService.submit(
401+
() -> {
402+
OfflineLicenseHelper offlineLicenseHelper =
403+
OfflineLicenseHelper.newWidevineInstance(
404+
drmConfiguration.licenseUri.toString(),
405+
drmConfiguration.forceDefaultLicenseUri,
406+
dataSourceFactory,
407+
drmConfiguration.licenseRequestHeaders,
408+
new DrmSessionEventListener.EventDispatcher());
409+
try {
410+
keySetId = offlineLicenseHelper.downloadLicense(format);
411+
} catch (DrmSession.DrmSessionException e) {
412+
drmSessionException = e;
413+
} finally {
414+
offlineLicenseHelper.release();
415+
new Handler(Looper.getMainLooper())
416+
.post(
417+
() -> {
418+
if (drmSessionException != null) {
419+
dialogHelper.onOfflineLicenseFetchedError(drmSessionException);
420+
} else {
421+
dialogHelper.onOfflineLicenseFetched(
422+
downloadHelper, checkNotNull(keySetId));
423+
}
424+
});
425+
}
426+
});
411427
}
412428
}
413429
}

demos/main/src/main/java/androidx/media3/demo/main/SampleChooserActivity.java

+35-24
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import android.content.pm.PackageManager;
2727
import android.content.res.AssetManager;
2828
import android.net.Uri;
29-
import android.os.AsyncTask;
3029
import android.os.Build;
3130
import android.os.Bundle;
31+
import android.os.Handler;
32+
import android.os.Looper;
3233
import android.text.TextUtils;
3334
import android.util.JsonReader;
3435
import android.view.Menu;
@@ -72,6 +73,8 @@
7273
import java.util.List;
7374
import java.util.Map;
7475
import java.util.UUID;
76+
import java.util.concurrent.ExecutorService;
77+
import java.util.concurrent.Executors;
7578

7679
/** An activity for selecting from a list of media samples. */
7780
public class SampleChooserActivity extends AppCompatActivity
@@ -282,34 +285,42 @@ private static boolean isNonNullAndChecked(@Nullable MenuItem menuItem) {
282285
return menuItem != null && menuItem.isChecked();
283286
}
284287

285-
private final class SampleListLoader extends AsyncTask<String, Void, List<PlaylistGroup>> {
288+
private final class SampleListLoader {
289+
290+
private final ExecutorService executorService;
286291

287292
private boolean sawError;
288293

289-
@OptIn(markerClass = androidx.media3.common.util.UnstableApi.class)
290-
@Override
291-
protected List<PlaylistGroup> doInBackground(String... uris) {
292-
List<PlaylistGroup> result = new ArrayList<>();
293-
Context context = getApplicationContext();
294-
DataSource dataSource = DemoUtil.getDataSourceFactory(context).createDataSource();
295-
for (String uri : uris) {
296-
DataSpec dataSpec = new DataSpec(Uri.parse(uri));
297-
InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
298-
try {
299-
readPlaylistGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
300-
} catch (Exception e) {
301-
Log.e(TAG, "Error loading sample list: " + uri, e);
302-
sawError = true;
303-
} finally {
304-
DataSourceUtil.closeQuietly(dataSource);
305-
}
306-
}
307-
return result;
294+
public SampleListLoader() {
295+
executorService = Executors.newSingleThreadExecutor();
308296
}
309297

310-
@Override
311-
protected void onPostExecute(List<PlaylistGroup> result) {
312-
onPlaylistGroups(result, sawError);
298+
@OptIn(markerClass = androidx.media3.common.util.UnstableApi.class)
299+
public void execute(String... uris) {
300+
executorService.execute(
301+
() -> {
302+
List<PlaylistGroup> result = new ArrayList<>();
303+
Context context = getApplicationContext();
304+
DataSource dataSource = DemoUtil.getDataSourceFactory(context).createDataSource();
305+
for (String uri : uris) {
306+
DataSpec dataSpec = new DataSpec(Uri.parse(uri));
307+
InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
308+
try {
309+
readPlaylistGroups(
310+
new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
311+
} catch (Exception e) {
312+
Log.e(TAG, "Error loading sample list: " + uri, e);
313+
sawError = true;
314+
} finally {
315+
DataSourceUtil.closeQuietly(dataSource);
316+
}
317+
}
318+
new Handler(Looper.getMainLooper())
319+
.post(
320+
() -> {
321+
onPlaylistGroups(result, sawError);
322+
});
323+
});
313324
}
314325

315326
private void readPlaylistGroups(JsonReader reader, List<PlaylistGroup> groups)

demos/transformer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ manual steps.
6161
(this will only appear if the AAR is present), then build and run the demo
6262
app and select a MediaPipe-based effect.
6363
64-
[Transformer]: https://developer.android.com/guide/topics/media/transforming-media
64+
[Transformer]: https://developer.android.com/media/media3/transformer
6565
[MediaPipe]: https://google.github.io/mediapipe/
6666
[build an AAR]: https://google.github.io/mediapipe/getting_started/android_archive_library.html

libraries/common/src/main/java/androidx/media3/common/AdOverlayInfo.java

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public AdOverlayInfo build() {
109109
* @deprecated Use {@link Builder} instead.
110110
*/
111111
@UnstableApi
112+
@SuppressWarnings("deprecation") // Intentionally using deprecated constructor
112113
@Deprecated
113114
public AdOverlayInfo(View view, @Purpose int purpose) {
114115
this(view, purpose, /* detailedReason= */ null);

libraries/common/src/main/java/androidx/media3/common/AdPlaybackState.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public AdGroup(long timeUs) {
117117
/* isServerSideInserted= */ false);
118118
}
119119

120+
@SuppressWarnings("deprecation") // Intentionally assigning deprecated field
120121
private AdGroup(
121122
long timeUs,
122123
int count,
@@ -502,8 +503,9 @@ private static long[] copyDurationsUsWithSpaceForAdCount(long[] durationsUs, int
502503
private static final String FIELD_ORIGINAL_COUNT = Util.intToStringMaxRadix(7);
503504
@VisibleForTesting static final String FIELD_MEDIA_ITEMS = Util.intToStringMaxRadix(8);
504505

506+
// Intentionally assigning deprecated field.
505507
// putParcelableArrayList actually supports null elements.
506-
@SuppressWarnings("nullness:argument")
508+
@SuppressWarnings({"deprecation", "nullness:argument"})
507509
@Override
508510
public Bundle toBundle() {
509511
Bundle bundle = new Bundle();

libraries/common/src/main/java/androidx/media3/common/Format.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
*
4343
* <p>When building formats, populate all fields whose values are known and relevant to the type of
4444
* format being constructed. For information about different types of format, see ExoPlayer's <a
45-
* href="https://developer.android.com/guide/topics/media/exoplayer/supported-formats">Supported
46-
* formats page</a>.
45+
* href="https://developer.android.com/media/media3/exoplayer/supported-formats">Supported formats
46+
* page</a>.
4747
*
4848
* <h2>Fields commonly relevant to all formats</h2>
4949
*

libraries/common/src/main/java/androidx/media3/common/ForwardingPlayer.java

+5
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ public boolean isDeviceMuted() {
860860
/**
861861
* @deprecated Use {@link #setDeviceVolume(int, int)} instead.
862862
*/
863+
@SuppressWarnings("deprecation") // Intentionally forwarding deprecated method
863864
@Deprecated
864865
@Override
865866
public void setDeviceVolume(int volume) {
@@ -875,6 +876,7 @@ public void setDeviceVolume(int volume, @C.VolumeFlags int flags) {
875876
/**
876877
* @deprecated Use {@link #increaseDeviceVolume(int)} instead.
877878
*/
879+
@SuppressWarnings("deprecation") // Intentionally forwarding deprecated method
878880
@Deprecated
879881
@Override
880882
public void increaseDeviceVolume() {
@@ -890,6 +892,7 @@ public void increaseDeviceVolume(@C.VolumeFlags int flags) {
890892
/**
891893
* @deprecated Use {@link #decreaseDeviceVolume(int)} instead.
892894
*/
895+
@SuppressWarnings("deprecation") // Intentionally forwarding deprecated method
893896
@Deprecated
894897
@Override
895898
public void decreaseDeviceVolume() {
@@ -905,6 +908,7 @@ public void decreaseDeviceVolume(@C.VolumeFlags int flags) {
905908
/**
906909
* @deprecated Use {@link #setDeviceMuted(boolean, int)} instead.
907910
*/
911+
@SuppressWarnings("deprecation") // Intentionally forwarding deprecated method
908912
@Deprecated
909913
@Override
910914
public void setDeviceMuted(boolean muted) {
@@ -1106,6 +1110,7 @@ public void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled) {
11061110
listener.onSkipSilenceEnabledChanged(skipSilenceEnabled);
11071111
}
11081112

1113+
@SuppressWarnings("deprecation") // Intentionally forwarding deprecated method
11091114
@Override
11101115
public void onCues(List<Cue> cues) {
11111116
listener.onCues(cues);

0 commit comments

Comments
 (0)