Skip to content

Commit

Permalink
chore(android): fix some android studio warning (#3290)
Browse files Browse the repository at this point in the history
Co-authored-by: olivier <[email protected]>
  • Loading branch information
freeboub and olivier authored Oct 12, 2023
1 parent 45dcded commit a4073d3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.brentvatne.exoplayer;

import android.annotation.TargetApi;
import android.content.Context;
import androidx.core.content.ContextCompat;
import android.util.AttributeSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.brentvatne.exoplayer;

import java.io.IOException;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.HttpDataSource.HttpDataSourceException;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy.LoadErrorInfo;
import com.google.android.exoplayer2.C;

public final class ReactExoplayerLoadErrorHandlingPolicy extends DefaultLoadErrorHandlingPolicy {
private int minLoadRetryCount = Integer.MAX_VALUE;
private final int minLoadRetryCount;

public ReactExoplayerLoadErrorHandlingPolicy(int minLoadRetryCount) {
super(minLoadRetryCount);
Expand All @@ -16,9 +14,11 @@ public ReactExoplayerLoadErrorHandlingPolicy(int minLoadRetryCount) {

@Override
public long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) {
String errorMessage = loadErrorInfo.exception.getMessage();

if (
loadErrorInfo.exception instanceof HttpDataSourceException &&
(loadErrorInfo.exception.getMessage() == "Unable to connect" || loadErrorInfo.exception.getMessage() == "Software caused connection abort")
errorMessage != null && (errorMessage.equals("Unable to connect") || errorMessage.equals("Software caused connection abort"))
) {
// Capture the error we get when there is no network connectivity and keep retrying it
return 1000; // Retry every second
Expand All @@ -33,4 +33,4 @@ public long getRetryDelayMsFor(LoadErrorInfo loadErrorInfo) {
public int getMinimumLoadableRetryCount(int dataType) {
return Integer.MAX_VALUE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.widget.FrameLayout;
import android.widget.ImageButton;

import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import androidx.activity.OnBackPressedCallback;

Expand Down Expand Up @@ -485,7 +486,7 @@ private void addPlayerControl() {
* Update the layout
* @param view view needs to update layout
*
* This is a workaround for the open bug in react-native: https://github.com/facebook/react-native/issues/17968
* This is a workaround for the open bug in react-native: <a href="https://github.com/facebook/react-native/issues/17968">...</a>
*/
private void reLayout(View view) {
if (view == null) return;
Expand All @@ -495,8 +496,8 @@ private void reLayout(View view) {
}

private class RNVLoadControl extends DefaultLoadControl {
private int availableHeapInBytes = 0;
private Runtime runtime;
private final int availableHeapInBytes;
private final Runtime runtime;
public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
super(allocator,
minBufferMs,
Expand All @@ -508,7 +509,7 @@ public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBuffer
backBufferDurationMs,
retainBackBufferFromKeyframe);
runtime = Runtime.getRuntime();
ActivityManager activityManager = (ActivityManager) themedReactContext.getSystemService(themedReactContext.ACTIVITY_SERVICE);
ActivityManager activityManager = (ActivityManager) themedReactContext.getSystemService(ThemedReactContext.ACTIVITY_SERVICE);
availableHeapInBytes = (int) Math.floor(activityManager.getMemoryClass() * maxHeapAllocationPercent * 1024 * 1024);
}

Expand Down Expand Up @@ -539,13 +540,6 @@ public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurat
}
}

private void startBufferCheckTimer() {
Player player = this.player;
VideoEventEmitter eventEmitter = this.eventEmitter;
Handler mainHandler = this.mainHandler;

}

private void initializePlayer() {
ReactExoplayerView self = this;
Activity activity = themedReactContext.getCurrentActivity();
Expand Down Expand Up @@ -734,7 +728,6 @@ private void finishPlayerInitialization() {
initializePlayerControl();
setControls(controls);
applyModifiers();
startBufferCheckTimer();
}

private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {
Expand Down Expand Up @@ -790,8 +783,8 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessi
}

MediaItem mediaItem = mediaItemBuilder.build();
MediaSource mediaSource = null;
DrmSessionManagerProvider drmProvider = null;
MediaSource mediaSource;
DrmSessionManagerProvider drmProvider;
if (drmSessionManager != null) {
drmProvider = new DrmSessionManagerProvider() {
@Override
Expand Down Expand Up @@ -868,9 +861,7 @@ private ArrayList<MediaSource> buildTextSources() {
Uri uri = Uri.parse(textTrack.getString("uri"));
MediaSource textSource = buildTextSource(title, uri, textTrack.getString("type"),
language);
if (textSource != null) {
textSources.add(textSource);
}
textSources.add(textSource);
}
return textSources;
}
Expand Down Expand Up @@ -1074,7 +1065,7 @@ public void onIsLoadingChanged(boolean isLoading) {
}

@Override
public void onEvents(Player player, Player.Events events) {
public void onEvents(@NonNull Player player, Player.Events events) {
if (events.contains(Player.EVENT_PLAYBACK_STATE_CHANGED) || events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)) {
int playbackState = player.getPlaybackState();
boolean playWhenReady = player.getPlayWhenReady();
Expand Down Expand Up @@ -1122,6 +1113,7 @@ public void onEvents(Player player, Player.Events events) {
text += "unknown";
break;
}
DebugLog.d(TAG, text);
}
}

Expand Down Expand Up @@ -1267,12 +1259,12 @@ private ArrayList<VideoTrack> getVideoTrackInfoFromManifest(int retryCount) {
final Uri sourceUri = this.srcUri;
final long startTime = this.contentStartTime * 1000 - 100; // s -> ms with 100ms offset

Future<ArrayList<VideoTrack>> result = es.submit(new Callable<ArrayList<VideoTrack>>() {
DataSource ds = dataSource;
Uri uri = sourceUri;
long startTimeUs = startTime * 1000; // ms -> us
Future<ArrayList<VideoTrack>> result = es.submit(new Callable<>() {
final DataSource ds = dataSource;
final Uri uri = sourceUri;
final long startTimeUs = startTime * 1000; // ms -> us

public ArrayList<VideoTrack> call() throws Exception {
public ArrayList<VideoTrack> call() {
ArrayList<VideoTrack> videoTracks = new ArrayList<>();
try {
DashManifest manifest = DashUtil.loadManifest(this.ds, this.uri);
Expand Down Expand Up @@ -1307,7 +1299,9 @@ public ArrayList<VideoTrack> call() throws Exception {
}
}
}
} catch (Exception e) {}
} catch (Exception e) {
DebugLog.w(TAG, "error in getVideoTrackInfoFromManifest:" + e.getMessage());
}
return null;
}
});
Expand All @@ -1319,7 +1313,9 @@ public ArrayList<VideoTrack> call() throws Exception {
}
es.shutdown();
return results;
} catch (Exception e) {}
} catch (Exception e) {
DebugLog.w(TAG, "error in getVideoTrackInfoFromManifest handling request:" + e.getMessage());
}

return null;
}
Expand Down Expand Up @@ -1359,15 +1355,11 @@ private void onBuffering(boolean buffering) {
}

isBuffering = buffering;
if (buffering) {
eventEmitter.buffering(true);
} else {
eventEmitter.buffering(false);
}
eventEmitter.buffering(buffering);
}

@Override
public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) {
public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, int reason) {
if (playerNeedsSource) {
// This will only occur if the user has performed a seek whilst in the error state. Update the
// resume position so that if the user then retries, playback will resume from the position to
Expand All @@ -1389,7 +1381,7 @@ public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.Posi
}

@Override
public void onTimelineChanged(Timeline timeline, int reason) {
public void onTimelineChanged(@NonNull Timeline timeline, int reason) {
// Do nothing.
}

Expand All @@ -1416,7 +1408,7 @@ public void onRepeatModeChanged(int repeatMode) {
}

@Override
public void onTracksChanged(Tracks tracks) {
public void onTracksChanged(@NonNull Tracks tracks) {
eventEmitter.textTracks(getTextTrackInfo());
eventEmitter.audioTracks(getAudioTrackInfo());
eventEmitter.videoTracks(getVideoTrackInfo());
Expand All @@ -1433,13 +1425,9 @@ public void onIsPlayingChanged(boolean isPlaying) {
}

@Override
public void onPlayerError(PlaybackException e) {
if (e == null) {
return;
}
public void onPlayerError(@NonNull PlaybackException e) {
String errorString = "ExoPlaybackException: " + PlaybackException.getErrorCodeName(e.errorCode);
String errorCode = "2" + String.valueOf(e.errorCode);
boolean needsReInitialization = false;
switch(e.errorCode) {
case PlaybackException.ERROR_CODE_DRM_DEVICE_REVOKED:
case PlaybackException.ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED:
Expand All @@ -1466,9 +1454,6 @@ public void onPlayerError(PlaybackException e) {
initializePlayer();
} else {
updateResumePosition();
if (needsReInitialization) {
initializePlayer();
}
}
}

Expand All @@ -1489,7 +1474,7 @@ public int getTrackRendererIndex(int trackType) {
}

@Override
public void onMetadata(Metadata metadata) {
public void onMetadata(@NonNull Metadata metadata) {
eventEmitter.timedMetadata(metadata);
}

Expand Down Expand Up @@ -1702,16 +1687,16 @@ public void setSelectedTrack(int trackType, String type, Dynamic value) {
if (groupIndex == C.INDEX_UNSET && trackType == C.TRACK_TYPE_VIDEO && groups.length != 0) { // Video auto
// Add all tracks as valid options for ABR to choose from
TrackGroup group = groups.get(0);
tracks = new ArrayList<Integer>(group.length);
ArrayList<Integer> allTracks = new ArrayList<Integer>(group.length);
tracks = new ArrayList<>(group.length);
ArrayList<Integer> allTracks = new ArrayList<>(group.length);
groupIndex = 0;
for (int j = 0; j < group.length; j++) {
allTracks.add(j);
}

// Valiate list of all tracks and add only supported formats
int supportedFormatLength = 0;
ArrayList<Integer> supportedTrackList = new ArrayList<Integer>();
ArrayList<Integer> supportedTrackList = new ArrayList<>();
for (int g = 0; g < allTracks.size(); g++) {
Format format = group.getFormat(g);
if (isFormatSupported(format)) {
Expand Down Expand Up @@ -1757,7 +1742,7 @@ private boolean isFormatSupported(Format format) {
if (mimeType == null) {
return true;
}
boolean isSupported = false;
boolean isSupported;
try {
MediaCodecInfo codecInfo = MediaCodecUtil.getDecoderInfo(mimeType, false, false);
isSupported = codecInfo.isVideoSizeAndRateSupportedV21(width, height, frameRate);
Expand Down Expand Up @@ -1913,7 +1898,7 @@ public void setBackBufferDurationMs(int backBufferDurationMs) {
}

public void setContentStartTime(int contentStartTime) {
this.contentStartTime = (long)contentStartTime;
this.contentStartTime = contentStartTime;
}

public void setDisableBuffering(boolean disableBuffering) {
Expand Down

0 comments on commit a4073d3

Please sign in to comment.