mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
play local video files
This commit is contained in:
parent
b9746c2b17
commit
053927a3ca
5 changed files with 97 additions and 7 deletions
|
@ -1,8 +1,13 @@
|
|||
package com.lagradost.cloudstream3.ui.download
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.format.Formatter.formatShortFileSize
|
||||
|
@ -11,6 +16,8 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
|
@ -27,8 +34,12 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
|||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
||||
import com.lagradost.cloudstream3.ui.player.BasicLink
|
||||
import com.lagradost.cloudstream3.ui.player.DownloadFileGenerator
|
||||
import com.lagradost.cloudstream3.ui.player.FullScreenPlayer
|
||||
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
||||
import com.lagradost.cloudstream3.ui.player.IPlayer
|
||||
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
||||
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment.Companion.clickCallback
|
||||
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
|
||||
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
|
||||
import com.lagradost.cloudstream3.ui.settings.Globals.TV
|
||||
|
@ -37,6 +48,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
|||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
||||
import com.lagradost.cloudstream3.utils.DataStore
|
||||
import com.lagradost.cloudstream3.utils.ExtractorUri
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||
|
@ -44,9 +56,9 @@ import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
|||
import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV
|
||||
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
|
||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||
import com.lagradost.safefile.SafeFile
|
||||
import java.net.URI
|
||||
|
||||
|
||||
const val DOWNLOAD_NAVIGATE_TO = "downloadpage"
|
||||
|
||||
class DownloadFragment : Fragment() {
|
||||
|
@ -89,11 +101,12 @@ class DownloadFragment : Fragment() {
|
|||
|
||||
val localBinding = FragmentDownloadsBinding.inflate(inflater, container, false)
|
||||
binding = localBinding
|
||||
return localBinding.root//inflater.inflate(R.layout.fragment_downloads, container, false)
|
||||
return localBinding.root
|
||||
}
|
||||
|
||||
private var downloadDeleteEventListener: ((Int) -> Unit)? = null
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
hideKeyboard()
|
||||
|
@ -266,6 +279,21 @@ class DownloadFragment : Fragment() {
|
|||
dialog.dismissSafe(activity)
|
||||
}
|
||||
}
|
||||
|
||||
binding?.openLocalVideoButton?.setOnClickListener {
|
||||
val intent = Intent()
|
||||
.setAction(Intent.ACTION_GET_CONTENT)
|
||||
.setType("video/*")
|
||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
.addFlags(FLAG_GRANT_READ_URI_PERMISSION) // Request temporary access
|
||||
try {
|
||||
videoResultLauncher.launch(Intent.createChooser(intent, getString(R.string.open_local_video)))
|
||||
}
|
||||
catch (t: ActivityNotFoundException) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding?.downloadList?.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||
val dy = scrollY - oldScrollY
|
||||
|
@ -280,4 +308,33 @@ class DownloadFragment : Fragment() {
|
|||
|
||||
fixPaddingStatusbar(binding?.downloadRoot)
|
||||
}
|
||||
|
||||
// Open local video from files using content provider x safeFile
|
||||
private val videoResultLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val intentData = result?.data?.data
|
||||
intentData.let { selectedVideoUri ->
|
||||
val name = SafeFile.fromUri(
|
||||
context ?: return@let ,
|
||||
selectedVideoUri ?: return@registerForActivityResult
|
||||
)?.name()
|
||||
|
||||
activity?.navigate(
|
||||
R.id.global_to_navigation_player,
|
||||
GeneratorPlayer.newInstance(
|
||||
DownloadFileGenerator(
|
||||
listOf(
|
||||
ExtractorUri(
|
||||
uri = selectedVideoUri,
|
||||
name = name ?: "Local video: $selectedVideoUri"
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
package com.lagradost.cloudstream3.ui.player
|
||||
|
||||
import com.lagradost.cloudstream3.amap
|
||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
||||
import com.lagradost.cloudstream3.utils.*
|
||||
import java.net.URI
|
||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||
import com.lagradost.cloudstream3.utils.ExtractorUri
|
||||
import com.lagradost.cloudstream3.utils.INFER_TYPE
|
||||
import com.lagradost.cloudstream3.utils.Qualities
|
||||
import com.lagradost.cloudstream3.utils.loadExtractor
|
||||
import com.lagradost.cloudstream3.utils.unshortenLinkSafe
|
||||
|
||||
/**
|
||||
* Used to open the player more easily with the LinkGenerator
|
||||
|
|
11
app/src/main/res/drawable/ic_network_stream.xml
Normal file
11
app/src/main/res/drawable/ic_network_stream.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="?attr/white"
|
||||
android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z" />
|
||||
|
||||
</vector>
|
|
@ -198,11 +198,29 @@
|
|||
</LinearLayout>
|
||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="bottom|end">
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/open_local_video_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="?attr/primaryGrayBackground"
|
||||
android:src="@drawable/video_play"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:tooltipText="@string/open_local_video"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:contentDescription="@string/open_local_video" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/download_stream_button"
|
||||
style="@style/ExtendedFloatingActionButton"
|
||||
android:text="@string/stream"
|
||||
android:textColor="?attr/textColor"
|
||||
app:icon="@drawable/netflix_play"
|
||||
tools:ignore="ContentDescription" />
|
||||
app:icon="@drawable/ic_network_stream"
|
||||
android:contentDescription="@string/stream" />
|
||||
</LinearLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -151,6 +151,7 @@
|
|||
<string name="download_format" translatable="false">%s - %s</string>
|
||||
<string name="update_started">Update Started</string>
|
||||
<string name="stream">Network stream</string>
|
||||
<string name="open_local_video">Open local video</string>
|
||||
<string name="error_loading_links_toast">Error Loading Links</string>
|
||||
<string name="links_reloaded_toast">Links Reloaded</string>
|
||||
<string name="download_storage_text">Internal Storage</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue