mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Merge pull request #5619 from Bnyro/master
feat: (re)add player actions for external player and pip
This commit is contained in:
commit
fc4794f395
@ -4,7 +4,9 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.pm.ResolveInfo
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
@ -48,4 +50,21 @@ object IntentHelper {
|
|||||||
.show(fragmentManager)
|
.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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ import com.github.libretube.extensions.togglePlayPauseState
|
|||||||
import com.github.libretube.extensions.updateParameters
|
import com.github.libretube.extensions.updateParameters
|
||||||
import com.github.libretube.helpers.BackgroundHelper
|
import com.github.libretube.helpers.BackgroundHelper
|
||||||
import com.github.libretube.helpers.ImageHelper
|
import com.github.libretube.helpers.ImageHelper
|
||||||
|
import com.github.libretube.helpers.IntentHelper
|
||||||
import com.github.libretube.helpers.NavBarHelper
|
import com.github.libretube.helpers.NavBarHelper
|
||||||
import com.github.libretube.helpers.NavigationHelper
|
import com.github.libretube.helpers.NavigationHelper
|
||||||
import com.github.libretube.helpers.PlayerHelper
|
import com.github.libretube.helpers.PlayerHelper
|
||||||
@ -602,26 +603,16 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
newShareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
newShareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.relPlayerShare.setOnLongClickListener {
|
binding.relPlayerExternalPlayer.setOnClickListener {
|
||||||
if (!this::streams.isInitialized || streams.hls == null) {
|
if (!this::streams.isInitialized || streams.hls == null) return@setOnClickListener
|
||||||
return@setOnLongClickListener true
|
|
||||||
}
|
|
||||||
|
|
||||||
// start an intent with video as mimetype using the hls stream
|
val context = requireContext()
|
||||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
lifecycleScope.launch {
|
||||||
setDataAndType(streams.hls.orEmpty().toUri(), "video/*")
|
val hlsStream = withContext(Dispatchers.IO) {
|
||||||
putExtra(Intent.EXTRA_TITLE, streams.title)
|
ProxyHelper.unwrapStreamUrl(streams.hls!!).toUri()
|
||||||
putExtra("title", streams.title)
|
}
|
||||||
putExtra("artist", streams.uploader)
|
IntentHelper.openWithExternalPlayer(context, hlsStream, streams.title, streams.uploader)
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
startActivity(intent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Toast.makeText(context, R.string.no_player_found, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.relPlayerBackground.setOnClickListener {
|
binding.relPlayerBackground.setOnClickListener {
|
||||||
@ -632,6 +623,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
playOnBackground()
|
playOnBackground()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.relPlayerPip.setOnClickListener {
|
||||||
|
PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams)
|
||||||
|
}
|
||||||
|
|
||||||
binding.relatedRecView.layoutManager = LinearLayoutManager(
|
binding.relatedRecView.layoutManager = LinearLayoutManager(
|
||||||
context,
|
context,
|
||||||
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
@ -66,6 +66,18 @@
|
|||||||
style="@style/PlayerActionsButton"
|
style="@style/PlayerActionsButton"
|
||||||
android:text="@string/audio"
|
android:text="@string/audio"
|
||||||
app:icon="@drawable/ic_headphones" />
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
@ -66,6 +66,18 @@
|
|||||||
style="@style/PlayerActionsButton"
|
style="@style/PlayerActionsButton"
|
||||||
android:text="@string/audio"
|
android:text="@string/audio"
|
||||||
app:icon="@drawable/ic_headphones" />
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
@ -470,6 +470,7 @@
|
|||||||
<string name="audio_language">Audio language</string>
|
<string name="audio_language">Audio language</string>
|
||||||
<string name="default_language">Default</string>
|
<string name="default_language">Default</string>
|
||||||
<string name="behavior_when_minimized">Behavior when minimized</string>
|
<string name="behavior_when_minimized">Behavior when minimized</string>
|
||||||
|
<string name="external_player">External player</string>
|
||||||
|
|
||||||
<!-- Backup & Restore Settings -->
|
<!-- Backup & Restore Settings -->
|
||||||
<string name="import_subscriptions_from">Import subscriptions from</string>
|
<string name="import_subscriptions_from">Import subscriptions from</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user