Skip to content

Commit

Permalink
Fix various nits / warnings from CI
Browse files Browse the repository at this point in the history
This includes:
- Using magic values in our enum
- Impliclt Locale issues
- Nullability checks
  • Loading branch information
DavidFair committed Jan 2, 2022
1 parent 179aeff commit f7e9999
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.Display;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.jellyfin.androidtv.R;
Expand Down Expand Up @@ -151,11 +152,11 @@ public PlayMethod getPlaybackMethod() {
return mPlaybackMethod;
}

public void setPlaybackMethod(PlayMethod value) {
public void setPlaybackMethod(@NonNull PlayMethod value) {
mPlaybackMethod = value;
}

public void setPlaybackSpeed(Double speed){
public void setPlaybackSpeed(@NonNull Double speed) {
mRequestedPlaybackSpeed = speed;
if (hasInitializedVideoManager()) {
mVideoManager.setPlaybackSpeed(speed);
Expand Down Expand Up @@ -184,14 +185,31 @@ public MediaSourceInfo getCurrentMediaSource() {
}
}

public StreamInfo getCurrentStreamInfo() { return mCurrentStreamInfo; }
public boolean canSeek() {return !isLiveTv;}
public boolean isLiveTv() { return isLiveTv; }
public int getSubtitleStreamIndex() {return (mCurrentOptions != null && mCurrentOptions.getSubtitleStreamIndex() != null) ? mCurrentOptions.getSubtitleStreamIndex() : -1; }
public @Nullable Integer getAudioStreamIndex() {
public StreamInfo getCurrentStreamInfo() {
return mCurrentStreamInfo;
}

public boolean canSeek() {
return !isLiveTv;
}

public boolean isLiveTv() {
return isLiveTv;
}

public int getSubtitleStreamIndex() {
return (mCurrentOptions != null && mCurrentOptions.getSubtitleStreamIndex() != null) ? mCurrentOptions.getSubtitleStreamIndex() : -1;
}

public @Nullable
Integer getAudioStreamIndex() {
return isTranscoding() ? mCurrentStreamInfo.getAudioStreamIndex() != null ? mCurrentStreamInfo.getAudioStreamIndex() : mCurrentOptions.getAudioStreamIndex() : mVideoManager.getAudioTrack() > -1 ? Integer.valueOf(mVideoManager.getAudioTrack()) : bestGuessAudioTrack(getCurrentMediaSource());
}
public List<SubtitleStreamInfo> getSubtitleStreams() { return mSubtitleStreams; }

public List<SubtitleStreamInfo> getSubtitleStreams() {
return mSubtitleStreams;
}

public SubtitleStreamInfo getSubtitleStreamInfo(int index) {
for (SubtitleStreamInfo info : mSubtitleStreams) {
if (info.getIndex() == index) return info;
Expand All @@ -200,20 +218,34 @@ public SubtitleStreamInfo getSubtitleStreamInfo(int index) {
return null;
}

public boolean isNativeMode() { return mVideoManager == null || mVideoManager.isNativeMode(); }
public boolean isNativeMode() {
return mVideoManager == null || mVideoManager.isNativeMode();
}

public boolean isTranscoding() {
return mCurrentStreamInfo != null && mCurrentStreamInfo.getPlayMethod() == PlayMethod.Transcode;
}

public boolean isTranscoding() { return mCurrentStreamInfo != null && mCurrentStreamInfo.getPlayMethod() == PlayMethod.Transcode; }
public boolean hasNextItem() {
return mCurrentIndex < mItems.size() - 1;
}

public boolean hasNextItem() { return mCurrentIndex < mItems.size() - 1; }
public BaseItemDto getNextItem() { return hasNextItem() ? mItems.get(mCurrentIndex+1) : null; }
public BaseItemDto getNextItem() {
return hasNextItem() ? mItems.get(mCurrentIndex + 1) : null;
}

public boolean isPlaying() {
// since playbackController is so closely tied to videoManager, check if it is playing too since they can fall out of sync
return mPlaybackState == PlaybackState.PLAYING && (mVideoManager == null || mVideoManager.isPlaying());
}

public void setAudioDelay(long value) { if (mVideoManager != null) mVideoManager.setAudioDelay(value);}
public long getAudioDelay() { return mVideoManager != null ? mVideoManager.getAudioDelay() : 0;}
public void setAudioDelay(long value) {
if (mVideoManager != null) mVideoManager.setAudioDelay(value);
}

public long getAudioDelay() {
return mVideoManager != null ? mVideoManager.getAudioDelay() : 0;
}

private Integer bestGuessAudioTrack(MediaSourceInfo info) {

Expand All @@ -223,7 +255,8 @@ private Integer bestGuessAudioTrack(MediaSourceInfo info) {
if (track.getType() == MediaStreamType.Video) {
videoFound = true;
} else {
if (videoFound && track.getType() == MediaStreamType.Audio) return track.getIndex();
if (videoFound && track.getType() == MediaStreamType.Audio)
return track.getIndex();
}
}
}
Expand All @@ -232,7 +265,8 @@ private Integer bestGuessAudioTrack(MediaSourceInfo info) {
}

public void playerErrorEncountered() {
if (mVideoManager.isNativeMode()) exoErrorEncountered = true; else vlcErrorEncountered = true;
if (mVideoManager.isNativeMode()) exoErrorEncountered = true;
else vlcErrorEncountered = true;

// reset the retry count if it's been more than 30s since previous error
if (playbackRetries > 0 && System.currentTimeMillis() - lastPlaybackError > 30000) {
Expand Down Expand Up @@ -309,17 +343,17 @@ private void setRefreshRate(MediaStream videoStream) {
Display.Mode best = findBestDisplayMode(videoStream);
if (best != null) {
Timber.i("*** Best refresh mode is: %s - %dx%d/%f",
best.getModeId(), best.getPhysicalWidth(), best.getPhysicalHeight(), best.getRefreshRate());
best.getModeId(), best.getPhysicalWidth(), best.getPhysicalHeight(), best.getRefreshRate());
if (current.getModeId() != best.getModeId()) {
Timber.i("*** Attempting to change refresh rate from %s/%s",current.getModeId(), current.getRefreshRate());
Timber.i("*** Attempting to change refresh rate from %s/%s", current.getModeId(), current.getRefreshRate());
WindowManager.LayoutParams params = TvApp.getApplication().getCurrentActivity().getWindow().getAttributes();
params.preferredDisplayModeId = best.getModeId();
TvApp.getApplication().getCurrentActivity().getWindow().setAttributes(params);
} else {
Timber.i("Display is already in best mode");
}
} else {
Timber.i("*** Unable to find display mode for refresh rate: %s",videoStream.getRealFrameRate());
Timber.i("*** Unable to find display mode for refresh rate: %s", videoStream.getRealFrameRate());
}


Expand All @@ -333,13 +367,11 @@ private void refreshCurrentPosition() {
if (isLiveTv && mCurrentProgramStartTime > 0) {
newPos = getRealTimeProgress();
// live tv
}
else if (mVideoManager != null) {
} else if (mVideoManager != null) {
if (!isPlaying() && mSeekPosition != -1) {
newPos = mSeekPosition;
// use seekedPosition until playback starts
}
else if (isPlaying()) {
} else if (isPlaying()) {
newPos = mVideoManager.getCurrentPosition();
mSeekPosition = -1;
// playback is happening - get current position and reset seekedPosition
Expand Down Expand Up @@ -369,7 +401,8 @@ private void play(long position, int transcodedSubtitle) {
case PAUSED:
// just resume
mVideoManager.play();
if (mVideoManager.isNativeMode()) mPlaybackState = PlaybackState.PLAYING; //won't get another onprepared call
if (mVideoManager.isNativeMode())
mPlaybackState = PlaybackState.PLAYING; //won't get another onprepared call
if (mFragment != null) {
mFragment.setFadingEnabled(true);
mFragment.setPlayPauseActionState(0);
Expand Down Expand Up @@ -462,15 +495,16 @@ public void onClick(DialogInterface dialog, int which) {
internalOptions.setItemId(item.getId());
internalOptions.setMediaSources(item.getMediaSources());
internalOptions.setMaxBitrate(Utils.getMaxBitrate());
if (exoErrorEncountered || (isLiveTv && !directStreamLiveTv)) internalOptions.setEnableDirectStream(false);
if (exoErrorEncountered || (isLiveTv && !directStreamLiveTv))
internalOptions.setEnableDirectStream(false);
internalOptions.setMaxAudioChannels(Utils.downMixAudio() ? 2 : null); //have to downmix at server
internalOptions.setSubtitleStreamIndex(transcodedSubtitle >= 0 ? transcodedSubtitle : null);
internalOptions.setMediaSourceId(transcodedSubtitle >= 0 ? getCurrentMediaSource().getId() : null);
DeviceProfile internalProfile = new BaseProfile();
if (DeviceUtils.is60() || userPreferences.getValue().get(UserPreferences.Companion.getAc3Enabled())) {
internalProfile = new ExoPlayerProfile(
isLiveTv,
userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled())
isLiveTv,
userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled())
);
ProfileHelper.addAc3Streaming(internalProfile, true);
Timber.i("*** Using extended Exoplayer profile options");
Expand All @@ -490,7 +524,7 @@ public void onClick(DialogInterface dialog, int which) {
mFragment.setCurrentTime(position);
}

long duration = getCurrentlyPlayingItem().getRunTimeTicks()!= null ? getCurrentlyPlayingItem().getRunTimeTicks() / 10000 : -1;
long duration = getCurrentlyPlayingItem().getRunTimeTicks() != null ? getCurrentlyPlayingItem().getRunTimeTicks() / 10000 : -1;
mVideoManager.setMetaDuration(duration);

break;
Expand All @@ -503,7 +537,7 @@ public int getBufferAmount() {

private void playInternal(final BaseItemDto item, final Long position, final VideoOptions vlcOptions, final VideoOptions internalOptions) {
if (isLiveTv) {
liveTvChannelName = " ("+item.getName()+")";
liveTvChannelName = " (" + item.getName() + ")";
updateTvProgramInfo();
TvManager.setLastLiveTvChannel(item.getId());
//Choose appropriate player now to avoid opening two streams
Expand All @@ -518,6 +552,7 @@ public void onResponse(StreamInfo response) {
useVlc = false;
startItem(item, position, response);
}

@Override
public void onError(Exception exception) {
handlePlaybackInfoError(exception);
Expand All @@ -535,6 +570,7 @@ public void onResponse(StreamInfo response) {
useVlc = true;
startItem(item, position, response);
}

@Override
public void onError(Exception exception) {
handlePlaybackInfoError(exception);
Expand Down Expand Up @@ -605,10 +641,11 @@ public void onResponse(StreamInfo internalResponse) {
// remove direct play profiles to force the transcode
final DeviceProfile save = internalOptions.getProfile();
DeviceProfile newProfile = new ExoPlayerProfile(
isLiveTv,
userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled())
isLiveTv,
userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled())
);
if (!Utils.downMixAudio()) ProfileHelper.addAc3Streaming(newProfile, true);
if (!Utils.downMixAudio())
ProfileHelper.addAc3Streaming(newProfile, true);
newProfile.setDirectPlayProfiles(new DirectPlayProfile[]{});
internalOptions.setProfile(newProfile);
Timber.i("Forcing transcode due to non-default audio chosen");
Expand Down Expand Up @@ -726,7 +763,7 @@ private void startItem(BaseItemDto item, long position, StreamInfo response) {
public void run() {
mVideoManager.start();
}
},750);
}, 750);

mStartPosition = position;

Expand Down Expand Up @@ -813,7 +850,8 @@ public void switchSubtitleStream(int index) {
break;
case Embed:
if (!mVideoManager.isNativeMode()) {
if (mFragment != null) mFragment.addManualSubtitles(null); // in case these were on
if (mFragment != null)
mFragment.addManualSubtitles(null); // in case these were on
if (!mVideoManager.setSubtitleTrack(index, getCurrentlyPlayingItem().getMediaStreams())) {
// error selecting internal subs
Utils.showToast(TvApp.getApplication(), TvApp.getApplication().getResources().getString(R.string.msg_unable_load_subs));
Expand Down Expand Up @@ -997,8 +1035,7 @@ public void onError(Exception exception) {
Utils.showToast(TvApp.getApplication(), TvApp.getApplication().getString(R.string.seek_error));
updateProgress = true;
pause();
}
else {
} else {
mVideoManager.play();
mPlaybackState = PlaybackState.PLAYING;
if (mFragment != null) {
Expand Down Expand Up @@ -1028,7 +1065,7 @@ public void skip(int msec) {
stopReportLoop();
refreshCurrentPosition(); // first time skip is called mCurrentPosition is made current, after that updateprogress = false
updateProgress = false; // turn this off so we can show where it will be jumping to
currentSkipPos = (currentSkipPos == 0 ? mCurrentPosition : currentSkipPos) + msec;
currentSkipPos = (currentSkipPos == 0 ? mCurrentPosition : currentSkipPos) + msec;

if (currentSkipPos < 0) {
currentSkipPos = 0;
Expand Down Expand Up @@ -1173,7 +1210,8 @@ public void removePreviousQueueItems() {
//Now - look at last item played and, if beyond default resume point, remove it too
Long duration = mCurrentStreamInfo != null ? mCurrentStreamInfo.getRunTimeTicks() : null;
if (duration != null && mediaManager.getValue().getCurrentVideoQueue().size() > 0) {
if (duration < 300000 || mCurrentPosition * 10000 > Math.floor(.90 * duration)) mediaManager.getValue().getCurrentVideoQueue().remove(0);
if (duration < 300000 || mCurrentPosition * 10000 > Math.floor(.90 * duration))
mediaManager.getValue().getCurrentVideoQueue().remove(0);
} else if (duration == null) mediaManager.getValue().getCurrentVideoQueue().remove(0);
setItems(mediaManager.getValue().getCurrentVideoQueue());
}
Expand All @@ -1193,7 +1231,7 @@ private void itemComplete() {
BaseItemDto curItem = getCurrentlyPlayingItem();

if (userPreferences.getValue().get(UserPreferences.Companion.getNextUpBehavior()) != NextUpBehavior.DISABLED
&& (curItem == null || curItem.getBaseItemType() != BaseItemType.Trailer)) {
&& (curItem == null || curItem.getBaseItemType() != BaseItemType.Trailer)) {
// Show "Next Up" fragment
spinnerOff = false;
mediaManager.getValue().setCurrentVideoQueue(mItems);
Expand Down Expand Up @@ -1307,7 +1345,7 @@ public void onEvent() {
}

refreshCurrentPosition();
if (mFragment != null){
if (mFragment != null) {
mFragment.setCurrentTime(mCurrentPosition);
mFragment.updateSubtitles(mCurrentPosition);
}
Expand Down Expand Up @@ -1339,7 +1377,9 @@ public int getZoomMode() {
return mVideoManager.getZoomMode();
}

public void setZoom(int mode) { mVideoManager.setZoom(mode); }
public void setZoom(int mode) {
mVideoManager.setZoom(mode);
}

public Integer translateVlcAudioId(Integer vlcId) {
return mVideoManager.translateVlcAudioId(vlcId);
Expand Down
Loading

0 comments on commit f7e9999

Please sign in to comment.