From c22224d541978effc375192c1ad165810e543dd4 Mon Sep 17 00:00:00 2001 From: rimthekid Date: Tue, 15 Mar 2022 12:06:42 -0400 Subject: [PATCH] open in vlc --- .../com/github/libretube/PlayerFragment.kt | 24 +++++++++++++++---- app/src/main/res/drawable/ic_vlc.xml | 7 ++++++ app/src/main/res/layout/fragment_player.xml | 24 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/ic_vlc.xml diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 79c7a00cd..e196000db 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -3,12 +3,12 @@ package com.github.libretube import android.Manifest import android.annotation.SuppressLint import android.app.Activity -import android.app.ActivityManager import android.content.Context import android.content.DialogInterface import android.content.Intent import android.content.pm.ActivityInfo import android.content.pm.PackageManager +import android.net.Uri import android.os.Build import android.os.Build.VERSION.SDK_INT import android.os.Bundle @@ -19,19 +19,15 @@ import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.WindowManager -import android.view.inputmethod.InputMethodManager import android.widget.* import androidx.appcompat.app.AlertDialog import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.app.ActivityCompat -import androidx.core.content.ContextCompat.getSystemService import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope -import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.adapters.TrendingAdapter @@ -449,6 +445,24 @@ class PlayerFragment : Fragment() { }else{ Toast.makeText(context,R.string.cannotDownload, Toast.LENGTH_SHORT).show() } + if (response.hls!=null){ + view.findViewById(R.id.relPlayer_vlc).setOnClickListener { + exoPlayer.pause() + try{ + val vlcRequestCode = 42 + val uri: Uri = Uri.parse(response.hls) + val vlcIntent = Intent(Intent.ACTION_VIEW) + vlcIntent.setPackage("org.videolan.vlc") + vlcIntent.setDataAndTypeAndNormalize(uri, "video/*") + vlcIntent.putExtra("title", response.title) + vlcIntent.putExtra("from_start", false) + vlcIntent.putExtra("position", exoPlayer.currentPosition) + startActivityForResult(vlcIntent, vlcRequestCode) + }catch(e: Exception){ + Toast.makeText(context, R.string.vlcerror, Toast.LENGTH_SHORT) + .show() + } + }} } } diff --git a/app/src/main/res/drawable/ic_vlc.xml b/app/src/main/res/drawable/ic_vlc.xml new file mode 100644 index 000000000..09154ca7e --- /dev/null +++ b/app/src/main/res/drawable/ic_vlc.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index d829fd801..f2828f96e 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -52,7 +52,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:weightSum="4" + android:weightSum="5" android:baselineAligned="false"> + + + + + Download is completed! Another Download is already in progress please wait till it\'s finished! Download Failed! + Open in VLC + Can\'t open in VLC. Maybe it\'s not installed yet? \ No newline at end of file