chore(android): fix various warnings (#3810)
* chore: add missing annotation * chore: remove unused import * chore: add final on members * chore: remove unused * chore: add missing annotations * chore: remove unused * chore: replace switch by if * chore: simplify lamba declaration * chore: more beautifull declaration * chore: rename variable considered as a typo * chore: remove deprecated & avoid multiple calls to the same function
This commit is contained in:
parent
cad5c4624c
commit
d987525b6d
@ -2,6 +2,7 @@ package com.brentvatne.exoplayer;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
@ -29,6 +30,7 @@ public enum AudioOutput {
|
|||||||
return streamType;
|
return streamType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")";
|
return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")";
|
||||||
|
@ -12,7 +12,6 @@ import androidx.media3.datasource.HttpDataSource;
|
|||||||
import androidx.media3.datasource.okhttp.OkHttpDataSource;
|
import androidx.media3.datasource.okhttp.OkHttpDataSource;
|
||||||
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter;
|
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter;
|
||||||
|
|
||||||
import com.brentvatne.common.toolbox.DebugLog;
|
|
||||||
import com.facebook.react.bridge.ReactContext;
|
import com.facebook.react.bridge.ReactContext;
|
||||||
import com.facebook.react.modules.network.CookieJarContainer;
|
import com.facebook.react.modules.network.CookieJarContainer;
|
||||||
import com.facebook.react.modules.network.ForwardingCookieHandler;
|
import com.facebook.react.modules.network.ForwardingCookieHandler;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.brentvatne.exoplayer;
|
package com.brentvatne.exoplayer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.media3.common.AdViewProvider;
|
import androidx.media3.common.AdViewProvider;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
@ -209,16 +211,6 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the view onto which video is rendered. This is either a {@link SurfaceView} (default)
|
|
||||||
* or a {@link TextureView} if the {@code use_texture_view} view attribute has been set to true.
|
|
||||||
*
|
|
||||||
* @return either a {@link SurfaceView} or a {@link TextureView}.
|
|
||||||
*/
|
|
||||||
public View getVideoSurfaceView() {
|
|
||||||
return surfaceView;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseTextureView(boolean useTextureView) {
|
public void setUseTextureView(boolean useTextureView) {
|
||||||
if (useTextureView != this.useTextureView) {
|
if (useTextureView != this.useTextureView) {
|
||||||
this.useTextureView = useTextureView;
|
this.useTextureView = useTextureView;
|
||||||
@ -272,7 +264,7 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
private final class ComponentListener implements Player.Listener {
|
private final class ComponentListener implements Player.Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCues(List<Cue> cues) {
|
public void onCues(@NonNull List<Cue> cues) {
|
||||||
subtitleLayout.setCues(cues);
|
subtitleLayout.setCues(cues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +290,7 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTracksChanged(Tracks tracks) {
|
public void onTracksChanged(@NonNull Tracks tracks) {
|
||||||
updateForCurrentTrackSelections(tracks);
|
updateForCurrentTrackSelections(tracks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,6 @@ import com.brentvatne.react.R;
|
|||||||
import com.brentvatne.receiver.AudioBecomingNoisyReceiver;
|
import com.brentvatne.receiver.AudioBecomingNoisyReceiver;
|
||||||
import com.brentvatne.receiver.BecomingNoisyListener;
|
import com.brentvatne.receiver.BecomingNoisyListener;
|
||||||
import com.facebook.react.bridge.LifecycleEventListener;
|
import com.facebook.react.bridge.LifecycleEventListener;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
|
||||||
import com.facebook.react.bridge.UiThreadUtil;
|
import com.facebook.react.bridge.UiThreadUtil;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
import com.google.ads.interactivemedia.v3.api.AdError;
|
import com.google.ads.interactivemedia.v3.api.AdError;
|
||||||
@ -158,7 +157,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
AdErrorEvent.AdErrorListener {
|
AdErrorEvent.AdErrorListener {
|
||||||
|
|
||||||
public static final double DEFAULT_MAX_HEAP_ALLOCATION_PERCENT = 1;
|
public static final double DEFAULT_MAX_HEAP_ALLOCATION_PERCENT = 1;
|
||||||
public static final double DEFAULT_MIN_BACK_BUFFER_MEMORY_RESERVE = 0;
|
|
||||||
public static final double DEFAULT_MIN_BUFFER_MEMORY_RESERVE = 0;
|
public static final double DEFAULT_MIN_BUFFER_MEMORY_RESERVE = 0;
|
||||||
|
|
||||||
private static final String TAG = "ReactExoplayerView";
|
private static final String TAG = "ReactExoplayerView";
|
||||||
@ -266,8 +264,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
private final Handler progressHandler = new Handler(Looper.getMainLooper()) {
|
private final Handler progressHandler = new Handler(Looper.getMainLooper()) {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
switch (msg.what) {
|
if (msg.what == SHOW_PROGRESS) {
|
||||||
case SHOW_PROGRESS:
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (playerControlView != null && isPlayingAd() && controls) {
|
if (playerControlView != null && isPlayingAd() && controls) {
|
||||||
playerControlView.hide();
|
playerControlView.hide();
|
||||||
@ -287,7 +284,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
msg = obtainMessage(SHOW_PROGRESS);
|
msg = obtainMessage(SHOW_PROGRESS);
|
||||||
sendMessageDelayed(msg, Math.round(mProgressUpdateInterval));
|
sendMessageDelayed(msg, Math.round(mProgressUpdateInterval));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -449,9 +445,9 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
//Handling the pauseButton click event
|
//Handling the pauseButton click event
|
||||||
ImageButton pauseButton = playerControlView.findViewById(R.id.exo_pause);
|
ImageButton pauseButton = playerControlView.findViewById(R.id.exo_pause);
|
||||||
pauseButton.setOnClickListener((View v) -> {
|
pauseButton.setOnClickListener((View v) ->
|
||||||
setPausedModifier(true);
|
setPausedModifier(true)
|
||||||
});
|
);
|
||||||
|
|
||||||
//Handling the fullScreenButton click event
|
//Handling the fullScreenButton click event
|
||||||
final ImageButton fullScreenButton = playerControlView.findViewById(R.id.exo_fullscreen);
|
final ImageButton fullScreenButton = playerControlView.findViewById(R.id.exo_fullscreen);
|
||||||
@ -780,7 +776,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MediaSource mediaSource;
|
MediaSource mediaSource;
|
||||||
if (mediaSourceList.size() == 0) {
|
if (mediaSourceList.isEmpty()) {
|
||||||
if (mediaSourceWithAds != null) {
|
if (mediaSourceWithAds != null) {
|
||||||
mediaSource = mediaSourceWithAds;
|
mediaSource = mediaSourceWithAds;
|
||||||
} else {
|
} else {
|
||||||
@ -919,12 +915,11 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
// When DRM fails using L1 we want to switch to L3
|
// When DRM fails using L1 we want to switch to L3
|
||||||
mediaDrm.setPropertyString("securityLevel", "L3");
|
mediaDrm.setPropertyString("securityLevel", "L3");
|
||||||
}
|
}
|
||||||
DefaultDrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder()
|
return new DefaultDrmSessionManager.Builder()
|
||||||
.setUuidAndExoMediaDrmProvider(uuid, (_uuid) -> mediaDrm)
|
.setUuidAndExoMediaDrmProvider(uuid, (_uuid) -> mediaDrm)
|
||||||
.setKeyRequestParameters(null)
|
.setKeyRequestParameters(null)
|
||||||
.setMultiSession(false)
|
.setMultiSession(false)
|
||||||
.build(drmCallback);
|
.build(drmCallback);
|
||||||
return drmSessionManager;
|
|
||||||
} catch (UnsupportedDrmException ex) {
|
} catch (UnsupportedDrmException ex) {
|
||||||
// Unsupported DRM exceptions are handled by the calling method
|
// Unsupported DRM exceptions are handled by the calling method
|
||||||
throw ex;
|
throw ex;
|
||||||
@ -945,7 +940,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
int type;
|
int type;
|
||||||
if ("rtsp".equals(overrideExtension)) {
|
if ("rtsp".equals(overrideExtension)) {
|
||||||
type = C.TYPE_RTSP;
|
type = CONTENT_TYPE_RTSP;
|
||||||
} else {
|
} else {
|
||||||
type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
|
type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
|
||||||
: uri.getLastPathSegment());
|
: uri.getLastPathSegment());
|
||||||
@ -970,7 +965,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
MediaSource.Factory mediaSourceFactory;
|
MediaSource.Factory mediaSourceFactory;
|
||||||
DrmSessionManagerProvider drmProvider;
|
DrmSessionManagerProvider drmProvider;
|
||||||
List<StreamKey> streamKeys = new ArrayList();
|
List<StreamKey> streamKeys = new ArrayList<>();
|
||||||
if (drmSessionManager != null) {
|
if (drmSessionManager != null) {
|
||||||
drmProvider = ((_mediaItem) -> drmSessionManager);
|
drmProvider = ((_mediaItem) -> drmSessionManager);
|
||||||
} else {
|
} else {
|
||||||
@ -1158,16 +1153,16 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
|
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
|
||||||
// Lower the volume
|
// Lower the volume
|
||||||
if (!view.muted) {
|
if (!view.muted) {
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() ->
|
||||||
view.player.setVolume(view.audioVolume * 0.8f);
|
view.player.setVolume(view.audioVolume * 0.8f)
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||||
// Raise it back to normal
|
// Raise it back to normal
|
||||||
if (!view.muted) {
|
if (!view.muted) {
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() ->
|
||||||
view.player.setVolume(view.audioVolume * 1);
|
view.player.setVolume(view.audioVolume * 1)
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1628,7 +1623,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerError(@NonNull PlaybackException e) {
|
public void onPlayerError(@NonNull PlaybackException e) {
|
||||||
String errorString = "ExoPlaybackException: " + PlaybackException.getErrorCodeName(e.errorCode);
|
String errorString = "ExoPlaybackException: " + PlaybackException.getErrorCodeName(e.errorCode);
|
||||||
String errorCode = "2" + String.valueOf(e.errorCode);
|
String errorCode = "2" + e.errorCode;
|
||||||
switch(e.errorCode) {
|
switch(e.errorCode) {
|
||||||
case PlaybackException.ERROR_CODE_DRM_DEVICE_REVOKED:
|
case PlaybackException.ERROR_CODE_DRM_DEVICE_REVOKED:
|
||||||
case PlaybackException.ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED:
|
case PlaybackException.ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED:
|
||||||
@ -1691,12 +1686,11 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
TimedMetadata timedMetadata = new TimedMetadata(frame.id, value);
|
TimedMetadata timedMetadata = new TimedMetadata(frame.id, value);
|
||||||
metadataArray.add(timedMetadata);
|
metadataArray.add(timedMetadata);
|
||||||
} else if (entry instanceof EventMessage) {
|
} else if (entry instanceof EventMessage eventMessage) {
|
||||||
EventMessage eventMessage = (EventMessage) entry;
|
|
||||||
TimedMetadata timedMetadata = new TimedMetadata(eventMessage.schemeIdUri, eventMessage.value);
|
TimedMetadata timedMetadata = new TimedMetadata(eventMessage.schemeIdUri, eventMessage.value);
|
||||||
metadataArray.add(timedMetadata);
|
metadataArray.add(timedMetadata);
|
||||||
} else {
|
} else {
|
||||||
DebugLog.d(TAG, "unhandled metadata " + entry.toString());
|
DebugLog.d(TAG, "unhandled metadata " + entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eventEmitter.timedMetadata(metadataArray);
|
eventEmitter.timedMetadata(metadataArray);
|
||||||
@ -1952,7 +1946,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
// Valiate list of all tracks and add only supported formats
|
// Valiate list of all tracks and add only supported formats
|
||||||
int supportedFormatLength = 0;
|
int supportedFormatLength = 0;
|
||||||
ArrayList<Integer> supportedTrackList = new ArrayList<>();
|
|
||||||
for (int g = 0; g < allTracks.size(); g++) {
|
for (int g = 0; g < allTracks.size(); g++) {
|
||||||
Format format = group.getFormat(g);
|
Format format = group.getFormat(g);
|
||||||
if (isFormatSupported(format)) {
|
if (isFormatSupported(format)) {
|
||||||
@ -1968,7 +1961,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
Format format = group.getFormat(k);
|
Format format = group.getFormat(k);
|
||||||
if (isFormatSupported(format)) {
|
if (isFormatSupported(format)) {
|
||||||
tracks.add(allTracks.get(k));
|
tracks.add(allTracks.get(k));
|
||||||
supportedTrackList.add(allTracks.get(k));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2285,7 +2277,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrmSessionManagerError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, Exception e) {
|
public void onDrmSessionManagerError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, @NonNull Exception e) {
|
||||||
DebugLog.d("DRM Info", "onDrmSessionManagerError");
|
DebugLog.d("DRM Info", "onDrmSessionManagerError");
|
||||||
eventEmitter.error("onDrmSessionManagerError", e, "3002");
|
eventEmitter.error("onDrmSessionManagerError", e, "3002");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.brentvatne.exoplayer;
|
package com.brentvatne.exoplayer;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -48,7 +50,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
private static final String PROP_SRC_TYPE = "type";
|
private static final String PROP_SRC_TYPE = "type";
|
||||||
private static final String PROP_DRM = "drm";
|
private static final String PROP_DRM = "drm";
|
||||||
private static final String PROP_DRM_TYPE = "type";
|
private static final String PROP_DRM_TYPE = "type";
|
||||||
private static final String PROP_DRM_LICENSESERVER = "licenseServer";
|
private static final String PROP_DRM_LICENSE_SERVER = "licenseServer";
|
||||||
private static final String PROP_DRM_HEADERS = "headers";
|
private static final String PROP_DRM_HEADERS = "headers";
|
||||||
private static final String PROP_SRC_HEADERS = "requestHeaders";
|
private static final String PROP_SRC_HEADERS = "requestHeaders";
|
||||||
private static final String PROP_RESIZE_MODE = "resizeMode";
|
private static final String PROP_RESIZE_MODE = "resizeMode";
|
||||||
@ -127,7 +129,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
public void setDRM(final ReactExoplayerView videoView, @Nullable ReadableMap drm) {
|
public void setDRM(final ReactExoplayerView videoView, @Nullable ReadableMap drm) {
|
||||||
if (drm != null && drm.hasKey(PROP_DRM_TYPE)) {
|
if (drm != null && drm.hasKey(PROP_DRM_TYPE)) {
|
||||||
String drmType = ReactBridgeUtils.safeGetString(drm, PROP_DRM_TYPE);
|
String drmType = ReactBridgeUtils.safeGetString(drm, PROP_DRM_TYPE);
|
||||||
String drmLicenseServer = ReactBridgeUtils.safeGetString(drm, PROP_DRM_LICENSESERVER);
|
String drmLicenseServer = ReactBridgeUtils.safeGetString(drm, PROP_DRM_LICENSE_SERVER);
|
||||||
ReadableArray drmHeadersArray = ReactBridgeUtils.safeGetArray(drm, PROP_DRM_HEADERS);
|
ReadableArray drmHeadersArray = ReactBridgeUtils.safeGetArray(drm, PROP_DRM_HEADERS);
|
||||||
if (drmType != null && drmLicenseServer != null && Util.getDrmUuid(drmType) != null) {
|
if (drmType != null && drmLicenseServer != null && Util.getDrmUuid(drmType) != null) {
|
||||||
UUID drmUUID = Util.getDrmUuid(drmType);
|
UUID drmUUID = Util.getDrmUuid(drmType);
|
||||||
@ -211,20 +213,22 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
videoView.setSrc(srcUri, startPositionMs, cropStartMs, cropEndMs, extension, headers, customMetadata);
|
videoView.setSrc(srcUri, startPositionMs, cropStartMs, cropEndMs, extension, headers, customMetadata);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int identifier = context.getResources().getIdentifier(
|
Resources resources = context.getResources();
|
||||||
|
String packageName = context.getPackageName();
|
||||||
|
int identifier = resources.getIdentifier(
|
||||||
uriString,
|
uriString,
|
||||||
"drawable",
|
"drawable",
|
||||||
context.getPackageName()
|
packageName
|
||||||
);
|
);
|
||||||
if (identifier == 0) {
|
if (identifier == 0) {
|
||||||
identifier = context.getResources().getIdentifier(
|
identifier = resources.getIdentifier(
|
||||||
uriString,
|
uriString,
|
||||||
"raw",
|
"raw",
|
||||||
context.getPackageName()
|
packageName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (identifier > 0) {
|
if (identifier > 0) {
|
||||||
Uri srcUri = RawResourceDataSource.buildRawResourceUri(identifier);
|
Uri srcUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE).path(Integer.toString(identifier)).build();
|
||||||
videoView.setRawSrc(srcUri, extension);
|
videoView.setRawSrc(srcUri, extension);
|
||||||
} else {
|
} else {
|
||||||
videoView.clearSrc();
|
videoView.clearSrc();
|
||||||
|
Loading…
Reference in New Issue
Block a user