mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
vlc test
This commit is contained in:
parent
eef78f8275
commit
7b81ec01b5
6 changed files with 127 additions and 13 deletions
|
@ -2,6 +2,8 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.lagradost.cloudstream3">
|
package="com.lagradost.cloudstream3">
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -19,6 +21,15 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/provider_paths"/>
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -6,6 +6,8 @@ import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
|
import com.lagradost.cloudstream3.UIHelper.checkWrite
|
||||||
|
import com.lagradost.cloudstream3.UIHelper.requestRW
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
private fun AppCompatActivity.backPressed(): Boolean {
|
private fun AppCompatActivity.backPressed(): Boolean {
|
||||||
|
@ -41,5 +43,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
R.id.navigation_home, R.id.navigation_search, R.id.navigation_notifications))
|
R.id.navigation_home, R.id.navigation_search, R.id.navigation_notifications))
|
||||||
//setupActionBarWithNavController(navController, appBarConfiguration)
|
//setupActionBarWithNavController(navController, appBarConfiguration)
|
||||||
navView.setupWithNavController(navController)
|
navView.setupWithNavController(navController)
|
||||||
|
|
||||||
|
if (!checkWrite()) {
|
||||||
|
requestRW()
|
||||||
|
if (checkWrite()) return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,13 @@
|
||||||
package com.lagradost.cloudstream3
|
package com.lagradost.cloudstream3
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultFragment
|
import com.lagradost.cloudstream3.ui.result.ResultFragment
|
||||||
|
|
||||||
|
@ -13,6 +17,21 @@ object UIHelper {
|
||||||
val Int.toDp: Int get() = (this / Resources.getSystem().displayMetrics.density).toInt()
|
val Int.toDp: Int get() = (this / Resources.getSystem().displayMetrics.density).toInt()
|
||||||
val Float.toDp: Float get() = (this / Resources.getSystem().displayMetrics.density)
|
val Float.toDp: Float get() = (this / Resources.getSystem().displayMetrics.density)
|
||||||
|
|
||||||
|
fun Activity.checkWrite(): Boolean {
|
||||||
|
return (ContextCompat.checkSelfPermission(this,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
== PackageManager.PERMISSION_GRANTED)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Activity.requestRW() {
|
||||||
|
ActivityCompat.requestPermissions(this,
|
||||||
|
arrayOf(
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||||
|
),
|
||||||
|
1337)
|
||||||
|
}
|
||||||
|
|
||||||
fun AppCompatActivity.loadResult(url: String, slug: String, apiName: String) {
|
fun AppCompatActivity.loadResult(url: String, slug: String, apiName: String) {
|
||||||
this.runOnUiThread {
|
this.runOnUiThread {
|
||||||
this.supportFragmentManager.beginTransaction()
|
this.supportFragmentManager.beginTransaction()
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
package com.lagradost.cloudstream3.ui.result
|
package com.lagradost.cloudstream3.ui.result
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.Intent.*
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.view.marginBottom
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.view.marginLeft
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.marginRight
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.view.marginTop
|
import androidx.core.net.toUri
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
@ -19,19 +24,18 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.model.GlideUrl
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
import com.bumptech.glide.request.RequestOptions.bitmapTransform
|
import com.bumptech.glide.request.RequestOptions.bitmapTransform
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiFromName
|
|
||||||
import com.lagradost.cloudstream3.AnimeLoadResponse
|
import com.lagradost.cloudstream3.AnimeLoadResponse
|
||||||
import com.lagradost.cloudstream3.LoadResponse
|
import com.lagradost.cloudstream3.LoadResponse
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.UIHelper.checkWrite
|
||||||
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
|
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
|
||||||
import com.lagradost.cloudstream3.UIHelper.getStatusBarHeight
|
import com.lagradost.cloudstream3.UIHelper.requestRW
|
||||||
import com.lagradost.cloudstream3.mvvm.Resource
|
import com.lagradost.cloudstream3.mvvm.Resource
|
||||||
import com.lagradost.cloudstream3.mvvm.observe
|
import com.lagradost.cloudstream3.mvvm.observe
|
||||||
import com.lagradost.cloudstream3.mvvm.safeApiCall
|
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||||
import kotlinx.android.synthetic.main.fragment_result.*
|
import kotlinx.android.synthetic.main.fragment_result.*
|
||||||
import kotlinx.android.synthetic.main.fragment_search.*
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
const val MAX_SYNO_LENGH = 600
|
const val MAX_SYNO_LENGH = 600
|
||||||
|
@ -128,9 +132,64 @@ class ResultFragment : Fragment() {
|
||||||
|
|
||||||
fun playEpisode(data: ArrayList<ExtractorLink>?) {
|
fun playEpisode(data: ArrayList<ExtractorLink>?) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
for (d in data) {
|
if (activity?.checkWrite() != true) {
|
||||||
println(d)
|
activity?.requestRW()
|
||||||
|
if (activity?.checkWrite() == true) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val outputDir = context!!.cacheDir // context being the Activity pointer
|
||||||
|
val outputFile = File.createTempFile("mirrorlist", ".m3u8", outputDir)
|
||||||
|
var text = "#EXTM3U";
|
||||||
|
for (d in data.sortedBy { -it.quality }) {
|
||||||
|
text += "\n#EXTINF:, ${d.name}\n${d.url}"
|
||||||
|
}
|
||||||
|
outputFile.writeText(text)
|
||||||
|
val VLC_PACKAGE = "org.videolan.vlc"
|
||||||
|
val VLC_INTENT_ACTION_RESULT = "org.videolan.vlc.player.result"
|
||||||
|
val VLC_COMPONENT: ComponentName =
|
||||||
|
ComponentName(VLC_PACKAGE, "org.videolan.vlc.gui.video.VideoPlayerActivity")
|
||||||
|
val REQUEST_CODE = 42
|
||||||
|
|
||||||
|
val FROM_START = -1
|
||||||
|
val FROM_PROGRESS = -2
|
||||||
|
|
||||||
|
|
||||||
|
val vlcIntent = Intent(VLC_INTENT_ACTION_RESULT)
|
||||||
|
|
||||||
|
vlcIntent.setPackage(VLC_PACKAGE)
|
||||||
|
// vlcIntent.setDataAndTypeAndNormalize(outputFile.toUri(), "video/*")
|
||||||
|
vlcIntent.addFlags(FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
|
||||||
|
vlcIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION)
|
||||||
|
vlcIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
vlcIntent.addFlags(FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||||
|
|
||||||
|
vlcIntent.setDataAndType(FileProvider.getUriForFile(activity!!,
|
||||||
|
activity!!.applicationContext.packageName + ".provider",
|
||||||
|
outputFile), "video/*")
|
||||||
|
|
||||||
|
val startId = FROM_PROGRESS
|
||||||
|
|
||||||
|
var position = startId
|
||||||
|
if (startId == FROM_START) {
|
||||||
|
position = 1
|
||||||
|
} else if (startId == FROM_PROGRESS) {
|
||||||
|
position = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
vlcIntent.putExtra("position", position)
|
||||||
|
//vlcIntent.putExtra("title", episodeName)
|
||||||
|
/*
|
||||||
|
if (subFile != null) {
|
||||||
|
val sfile: Unit = Android.Net.Uri.FromFile(subFile)
|
||||||
|
vlcIntent.PutExtra("subtitles_location", sfile.Path)
|
||||||
|
//vlcIntent.PutExtra("sub_mrl", "file://" sfile.Path);
|
||||||
|
//vlcIntent.PutExtra("subtitles_location", "file:///storage/emulated/0/Download/mirrorlist.srt");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
vlcIntent.setComponent(VLC_COMPONENT)
|
||||||
|
|
||||||
|
//lastId = episodeId
|
||||||
|
activity?.startActivityForResult(vlcIntent, REQUEST_CODE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +257,7 @@ class ResultFragment : Fragment() {
|
||||||
i,
|
i,
|
||||||
apiName,
|
apiName,
|
||||||
(slug + index).hashCode(),
|
(slug + index).hashCode(),
|
||||||
(index * 0.1f),//TODO TEST; REMOVE
|
0f,//(index * 0.1f),//TODO TEST; REMOVE
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(result_episodes.adapter as EpisodeAdapter).cardList = episodes
|
(result_episodes.adapter as EpisodeAdapter).cardList = episodes
|
||||||
|
|
|
@ -33,7 +33,7 @@ class ResultViewModel : ViewModel() {
|
||||||
}
|
}
|
||||||
val links = ArrayList<ExtractorLink>()
|
val links = ArrayList<ExtractorLink>()
|
||||||
val data = safeApiCall {
|
val data = safeApiCall {
|
||||||
getApiFromName(episode.apiName).loadLinks(episode.data, false) { //TODO IMPLEMENT CASTING
|
getApiFromName(episode.apiName).loadLinks(episode.data, true) { //TODO IMPLEMENT CASTING
|
||||||
links.add(it)
|
links.add(it)
|
||||||
_allEpisodes.value?.set(episode.id, links)
|
_allEpisodes.value?.set(episode.id, links)
|
||||||
// _allEpisodes.value?.get(episode.id)?.add(it)
|
// _allEpisodes.value?.get(episode.id)?.add(it)
|
||||||
|
|
18
app/src/main/res/xml/provider_paths.xml
Normal file
18
app/src/main/res/xml/provider_paths.xml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<external-path
|
||||||
|
name="external"
|
||||||
|
path="." />
|
||||||
|
<external-files-path
|
||||||
|
name="external_files"
|
||||||
|
path="." />
|
||||||
|
<cache-path
|
||||||
|
name="cache"
|
||||||
|
path="." />
|
||||||
|
<external-cache-path
|
||||||
|
name="external_cache"
|
||||||
|
path="." />
|
||||||
|
<files-path
|
||||||
|
name="files"
|
||||||
|
path="." />
|
||||||
|
</paths>
|
Loading…
Reference in a new issue