diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-10-09 14:08:48 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-10-09 14:08:48 +0000 |
commit | 4de457cd0207dc1fcac1487d046565df06c3d165 (patch) | |
tree | 9df8170a54fea71ab43572d8150e1b6a78fee208 /app/src/main/java | |
parent | f12dea156fbe08b3b8ad64d153c8aedc75bf024e (diff) | |
download | infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.tar infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.tar.gz infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.tar.bz2 infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.tar.lz infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.tar.xz infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.tar.zst infinity-for-reddit-4de457cd0207dc1fcac1487d046565df06c3d165.zip |
Loop video option is available for autoplaying videos.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java | 7 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LoopAvailableExoCreator.java | 35 |
2 files changed, 39 insertions, 3 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index 604aa32f..2b8351bb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -25,6 +25,7 @@ import im.ene.toro.exoplayer.ExoCreator; import im.ene.toro.exoplayer.MediaSourceBuilder; import im.ene.toro.exoplayer.ToroExo; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.LoopAvailableExoCreator; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -309,10 +310,10 @@ class AppModule { @Provides @Singleton - ExoCreator provideExoCreator(SimpleCache simpleCache) { - Config config = new Config.Builder(mApplication).setMediaSourceBuilder(MediaSourceBuilder.LOOPING).setCache(simpleCache) + ExoCreator provideExoCreator(SimpleCache simpleCache, @Named("default") SharedPreferences sharedPreferences) { + Config config = new Config.Builder(mApplication).setMediaSourceBuilder(MediaSourceBuilder.DEFAULT).setCache(simpleCache) .build(); - return ToroExo.with(mApplication).getCreator(config); + return new LoopAvailableExoCreator(ToroExo.with(mApplication), config, sharedPreferences); } @Provides diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LoopAvailableExoCreator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LoopAvailableExoCreator.java new file mode 100644 index 00000000..5ccda4be --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LoopAvailableExoCreator.java @@ -0,0 +1,35 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; + +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.SimpleExoPlayer; + +import im.ene.toro.exoplayer.Config; +import im.ene.toro.exoplayer.DefaultExoCreator; +import im.ene.toro.exoplayer.ToroExo; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; + +public class LoopAvailableExoCreator extends DefaultExoCreator { + private final SharedPreferences sharedPreferences; + + public LoopAvailableExoCreator(@NonNull ToroExo toro, @NonNull Config config, SharedPreferences sharedPreferences) { + super(toro, config); + this.sharedPreferences = sharedPreferences; + } + + @NonNull + @Override + public SimpleExoPlayer createPlayer() { + SimpleExoPlayer player = super.createPlayer(); + if (sharedPreferences.getBoolean(SharedPreferencesUtils.LOOP_VIDEO, true)) { + player.setRepeatMode(Player.REPEAT_MODE_ALL); + } else { + player.setRepeatMode(Player.REPEAT_MODE_OFF); + } + + return player; + } +} |