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 allow playback during call #4862

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -102,6 +102,7 @@ object PreferenceKeys {
const val SB_HIGHLIGHTS = "sb_highlights"
const val SHOW_TIME_LEFT = "show_time_left"
const val FALLBACK_PIPED_PROXY = "fallback_piped_proxy"
const val ALLOW_PLAYBACK_DURING_CALL = "playback_during_call"

/**
* Background mode
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ object PlayerHelper {
true
)

private val handleAudioFocus
get() = !PreferenceHelper.getBoolean(
PreferenceKeys.ALLOW_PLAYBACK_DURING_CALL,
false
)

fun getDefaultResolution(context: Context, isFullscreen: Boolean): Int? {
var prefKey = if (NetworkHelper.isNetworkMetered(context)) {
PreferenceKeys.DEFAULT_RESOLUTION_MOBILE
Expand Down Expand Up @@ -428,16 +434,6 @@ object PlayerHelper {
}
}

/**
* Get the audio attributes to use for the player
*/
fun getAudioAttributes(): AudioAttributes {
return AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.AUDIO_CONTENT_TYPE_MOVIE)
.build()
}

/**
* Create a basic player, that is used for all types of playback situations inside the app
*/
Expand All @@ -448,14 +444,18 @@ object PlayerHelper {
Executors.newCachedThreadPool()
)
val dataSourceFactory = DefaultDataSource.Factory(context, cronetDataSourceFactory)
val audioAttributes = AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.AUDIO_CONTENT_TYPE_MOVIE)
.build()

return ExoPlayer.Builder(context)
.setUsePlatformDiagnostics(false)
.setMediaSourceFactory(DefaultMediaSourceFactory(dataSourceFactory))
.setTrackSelector(trackSelector)
.setHandleAudioBecomingNoisy(true)
.setLoadControl(getLoadControl())
.setAudioAttributes(getAudioAttributes(), true)
.setAudioAttributes(audioAttributes, handleAudioFocus)
.setUsePlatformDiagnostics(false)
.build()
.apply {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_call.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20.01,15.38c-1.23,0 -2.42,-0.2 -3.53,-0.56 -0.35,-0.12 -0.74,-0.03 -1.01,0.24l-1.57,1.97c-2.83,-1.35 -5.48,-3.9 -6.89,-6.83l1.95,-1.66c0.27,-0.28 0.35,-0.67 0.24,-1.02 -0.37,-1.11 -0.56,-2.3 -0.56,-3.53 0,-0.54 -0.45,-0.99 -0.99,-0.99H4.19C3.65,3 3,3.24 3,3.99 3,13.28 10.73,21 20.01,21c0.71,0 0.99,-0.63 0.99,-1.18v-3.45c0,-0.54 -0.45,-0.99 -0.99,-0.99z" />
</vector>
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 @@ -447,6 +447,8 @@
<string name="remove_watched_videos">Remove watched videos</string>
<string name="no_fullscreen_resolution">No-Fullscreen resolution</string>
<string name="same_as_fullscreen">Same as fullscreen</string>
<string name="playback_during_call">Continue playback during phone call</string>
<string name="playback_during_call_summary">Note that this also affects the app to not handle any kind of audio focus anymore.</string>

<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/player_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@
app:key="pause_screen_off"
app:title="@string/pauseOnScreenOff" />

<SwitchPreferenceCompat
android:icon="@drawable/ic_call"
android:summary="@string/playback_during_call_summary"
app:defaultValue="false"
app:key="playback_during_call"
app:title="@string/playback_during_call" />

</PreferenceCategory>

</PreferenceScreen>
Loading