feat: (re)add player actions for external player and pip

This commit is contained in:
Bnyro 2024-02-11 12:39:48 +01:00
parent 58029a1313
commit f87e22dd3f
5 changed files with 57 additions and 18 deletions

View File

@ -4,7 +4,9 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.core.net.toUri
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
@ -48,4 +50,21 @@ object IntentHelper {
.show(fragmentManager)
}
}
fun openWithExternalPlayer(context: Context, uri: Uri, title: String?, uploader: String?) {
// start an intent with video as mimetype using the hls stream
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "video/*")
putExtra(Intent.EXTRA_TITLE, title)
putExtra("title", title)
putExtra("artist", uploader)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(intent)
} catch (e: Exception) {
Toast.makeText(context, R.string.no_player_found, Toast.LENGTH_SHORT).show()
}
}
}

View File

@ -78,6 +78,7 @@ import com.github.libretube.extensions.togglePlayPauseState
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.BackgroundHelper
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.IntentHelper
import com.github.libretube.helpers.NavBarHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.helpers.PlayerHelper
@ -602,26 +603,16 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
newShareDialog.show(childFragmentManager, ShareDialog::class.java.name)
}
binding.relPlayerShare.setOnLongClickListener {
if (!this::streams.isInitialized || streams.hls == null) {
return@setOnLongClickListener true
}
binding.relPlayerExternalPlayer.setOnClickListener {
if (!this::streams.isInitialized || streams.hls == null) return@setOnClickListener
// start an intent with video as mimetype using the hls stream
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(streams.hls.orEmpty().toUri(), "video/*")
putExtra(Intent.EXTRA_TITLE, streams.title)
putExtra("title", streams.title)
putExtra("artist", streams.uploader)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val context = requireContext()
lifecycleScope.launch {
val hlsStream = withContext(Dispatchers.IO) {
ProxyHelper.unwrapStreamUrl(streams.hls!!).toUri()
}
IntentHelper.openWithExternalPlayer(context, hlsStream, streams.title, streams.uploader)
}
try {
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(context, R.string.no_player_found, Toast.LENGTH_SHORT).show()
}
true
}
binding.relPlayerBackground.setOnClickListener {
@ -632,6 +623,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playOnBackground()
}
binding.relPlayerPip.setOnClickListener {
PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams)
}
binding.relatedRecView.layoutManager = LinearLayoutManager(
context,
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {

View File

@ -66,6 +66,18 @@
style="@style/PlayerActionsButton"
android:text="@string/audio"
app:icon="@drawable/ic_headphones" />
<com.google.android.material.button.MaterialButton
android:id="@+id/relPlayer_external_player"
style="@style/PlayerActionsButton"
android:text="@string/external_player"
app:icon="@drawable/ic_video" />
<com.google.android.material.button.MaterialButton
android:id="@+id/relPlayer_pip"
style="@style/PlayerActionsButton"
android:text="@string/picture_in_picture"
app:icon="@drawable/ic_open" />
</LinearLayout>
</HorizontalScrollView>

View File

@ -66,6 +66,18 @@
style="@style/PlayerActionsButton"
android:text="@string/audio"
app:icon="@drawable/ic_headphones" />
<com.google.android.material.button.MaterialButton
android:id="@+id/relPlayer_external_player"
style="@style/PlayerActionsButton"
android:text="@string/external_player"
app:icon="@drawable/ic_video" />
<com.google.android.material.button.MaterialButton
android:id="@+id/relPlayer_pip"
style="@style/PlayerActionsButton"
android:text="@string/picture_in_picture"
app:icon="@drawable/ic_open" />
</LinearLayout>
</HorizontalScrollView>

View File

@ -470,6 +470,7 @@
<string name="audio_language">Audio language</string>
<string name="default_language">Default</string>
<string name="behavior_when_minimized">Behavior when minimized</string>
<string name="external_player">External player</string>
<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>