Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to autoplay videos in playlist #4829

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ object PreferenceKeys {
const val ALTERNATIVE_PLAYER_LAYOUT = "alternative_player_layout"
const val USE_HLS_OVER_DASH = "use_hls"
const val QUEUE_AUTO_INSERT_RELATED = "queue_insert_related_videos"
const val AUTOPLAY_PLAYLISTS = "autoplay_playlists"
const val PLAYER_SWIPE_CONTROLS = "player_swipe_controls"
const val PLAYER_PINCH_CONTROL = "player_pinch_control"
const val CAPTIONS_SIZE = "captions_size"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ object PlayerHelper {
true
)

fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean {
return autoPlayEnabled || (PreferenceHelper.getBoolean(PreferenceKeys.AUTOPLAY_PLAYLISTS, true) && isPlaylist)
Bnyro marked this conversation as resolved.
Show resolved Hide resolved
}

fun getDefaultResolution(context: Context): String {
val prefKey = if (NetworkHelper.isNetworkMetered(context)) {
PreferenceKeys.DEFAULT_RESOLUTION_MOBILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class OnlinePlayerService : LifecycleService() {
override fun onPlaybackStateChanged(state: Int) {
when (state) {
Player.STATE_ENDED -> {
if (PlayerHelper.autoPlayEnabled && !isTransitioning) playNextVideo()
if (PlayerHelper.shouldPlayNextVideo(playlistId != null) && !isTransitioning) playNextVideo()
}

Player.STATE_IDLE -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
exoPlayer.setPlaybackSpeed(1f)
}

// check if video has ended, next video is available and autoplay is enabled.
// check if video has ended, next video is available and autoplay is enabled/the video is part of a played playlist.
if (playbackState == Player.STATE_ENDED) {
if (!isTransitioning && PlayerHelper.autoPlayEnabled) {
if (!isTransitioning && PlayerHelper.shouldPlayNextVideo(playlistId != null)) {
isTransitioning = true
if (PlayerHelper.autoPlayCountdown) {
showAutoPlayCountdown()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
<string name="bookmark">Bookmark</string>
<string name="clear_bookmarks">Clear bookmarks</string>
<string name="queue_insert_related_videos">Insert related videos</string>
<string name="autoplay_playlists">Autoplay playlists</string>
<string name="autoplay_playlists_summary">Play next video in playlists regardless of autoplay settings</string>
FineFindus marked this conversation as resolved.
Show resolved Hide resolved
<string name="local_playlists">Local playlists</string>
<string name="brightness">Brightness</string>
<string name="volume">Volume</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/player_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
android:title="@string/queue_insert_related_videos"
app:key="queue_insert_related_videos" />

<SwitchPreferenceCompat
android:defaultValue="true"
Bnyro marked this conversation as resolved.
Show resolved Hide resolved
android:title="@string/autoplay_playlists"
android:summary="@string/autoplay_playlists_summary"
app:key="autoplay_playlists" />

</PreferenceCategory>


Expand Down