Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Commit

Permalink
Tidy code
Browse files Browse the repository at this point in the history
 - Ran a code formatter to sort out my spacing
 - Refactored hasMediaPlayerAudioTracks(..)
 - Injected UserAgent rather than hardcoding a string
  • Loading branch information
Alex Eyre committed Oct 6, 2018
1 parent 0bbc337 commit 6c23e42
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.floens.chan.core.cache.FileCacheDownloader;
import org.floens.chan.core.cache.FileCacheListener;
import org.floens.chan.core.cache.FileCacheProvider;
import org.floens.chan.core.di.UserAgentProvider;
import org.floens.chan.core.model.PostImage;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.utils.AndroidUtils;
Expand Down Expand Up @@ -80,6 +81,9 @@ public enum Mode {
@Inject
ImageLoader imageLoader;

@Inject
UserAgentProvider userAgent;

private ImageView playView;

private PostImage postImage;
Expand Down Expand Up @@ -178,8 +182,8 @@ public CustomScaleImageView findScaleImageView() {

public void setVolume(boolean muted) {
final float volume = muted ? 0f : 1f;
if(ChanSettings.videoUseExoplayer.get()){
if(exoPlayer != null) {
if (ChanSettings.videoUseExoplayer.get()) {
if (exoPlayer != null) {
exoPlayer.getAudioComponent().setVolume(volume);
}
} else {
Expand Down Expand Up @@ -413,14 +417,14 @@ private void setVideoFile(final File file) {
exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext());
exoVideoView.setPlayer(exoPlayer);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(),
Util.getUserAgent(getContext(),"Clover"));
Util.getUserAgent(getContext(), userAgent.getUserAgent()));
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(android.net.Uri.fromFile(file));

exoPlayer.setRepeatMode(Player.REPEAT_MODE_ALL); //Repeat forever

exoPlayer.prepare(videoSource);
callback.onVideoLoaded(this,hasMediaPlayerAudioTracks(exoPlayer));
callback.onVideoLoaded(this, hasMediaPlayerAudioTracks(exoPlayer));
addView(exoVideoView);
exoPlayer.setPlayWhenReady(true);
} else {
Expand Down Expand Up @@ -484,11 +488,7 @@ private boolean hasMediaPlayerAudioTracks(MediaPlayer mediaPlayer) {
}

private boolean hasMediaPlayerAudioTracks(ExoPlayer mediaPlayer) {
if(mediaPlayer.getAudioComponent() == null) {
return false;
} else {
return true;
}
return mediaPlayer.getAudioComponent() != null;
}

private void onVideoError() {
Expand Down

0 comments on commit 6c23e42

Please sign in to comment.