mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
exoplayer is now ok needs a lot more work though
This commit is contained in:
parent
972d1497a3
commit
64de3dd54d
2
.idea/deploymentTargetDropDown.xml
generated
2
.idea/deploymentTargetDropDown.xml
generated
@ -12,7 +12,7 @@
|
|||||||
</deviceKey>
|
</deviceKey>
|
||||||
</Target>
|
</Target>
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
</runningDeviceTargetSelectedWithDropDown>
|
||||||
<timeTargetWasSelectedWithDropDown value="2021-12-12T11:35:38.344385Z" />
|
<timeTargetWasSelectedWithDropDown value="2021-12-12T14:57:43.909907Z" />
|
||||||
<runningDeviceTargetsSelectedWithDialog>
|
<runningDeviceTargetsSelectedWithDialog>
|
||||||
<Target>
|
<Target>
|
||||||
<type value="RUNNING_DEVICE_TARGET" />
|
<type value="RUNNING_DEVICE_TARGET" />
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.btcland.libretube
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import com.google.android.exoplayer2.ui.PlayerView
|
||||||
|
|
||||||
|
internal class CustomExoPlayerView(
|
||||||
|
context: Context, attributeSet: AttributeSet? = null
|
||||||
|
) : PlayerView(context, attributeSet) {
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
showController()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
@ -5,9 +5,21 @@ import androidx.fragment.app.Fragment
|
|||||||
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 android.widget.ProgressBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.constraintlayout.widget.ConstraintSet
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.google.android.exoplayer2.ExoPlayer
|
||||||
|
import com.google.android.exoplayer2.MediaItem
|
||||||
|
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||||
|
import com.google.android.exoplayer2.source.MediaSource
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.ui.PlayerView
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import okhttp3.*
|
||||||
|
import java.io.IOException
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
@ -27,6 +39,13 @@ class PlayerFragment : Fragment() {
|
|||||||
private var lastProgress: Float = 0.toFloat()
|
private var lastProgress: Float = 0.toFloat()
|
||||||
private var sId: Int=0
|
private var sId: Int=0
|
||||||
private var eId: Int=0
|
private var eId: Int=0
|
||||||
|
|
||||||
|
|
||||||
|
private lateinit var exoPlayerView: PlayerView
|
||||||
|
private lateinit var motionLayout: SingleViewTouchableMotionLayout
|
||||||
|
private lateinit var exoPlayer: ExoPlayer
|
||||||
|
private lateinit var mediaSource: MediaSource
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
@ -46,7 +65,8 @@ class PlayerFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
val playerMotionLayout = view.findViewById<SingleViewTouchableMotionLayout>(R.id.playerMotionLayout)
|
val playerMotionLayout = view.findViewById<SingleViewTouchableMotionLayout>(R.id.playerMotionLayout)
|
||||||
|
motionLayout = playerMotionLayout
|
||||||
|
exoPlayerView = view.findViewById(R.id.player)
|
||||||
view.findViewById<TextView>(R.id.textTest).text = videoId
|
view.findViewById<TextView>(R.id.textTest).text = videoId
|
||||||
playerMotionLayout.addTransitionListener(object: MotionLayout.TransitionListener {
|
playerMotionLayout.addTransitionListener(object: MotionLayout.TransitionListener {
|
||||||
override fun onTransitionStarted(
|
override fun onTransitionStarted(
|
||||||
@ -90,8 +110,11 @@ class PlayerFragment : Fragment() {
|
|||||||
})
|
})
|
||||||
playerMotionLayout.progress=1.toFloat()
|
playerMotionLayout.progress=1.toFloat()
|
||||||
playerMotionLayout.transitionToStart()
|
playerMotionLayout.transitionToStart()
|
||||||
|
fetchJson(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Use this factory method to create a new instance of
|
* Use this factory method to create a new instance of
|
||||||
@ -111,4 +134,48 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initPlayer(view: View,url: String){
|
||||||
|
exoPlayer = ExoPlayer.Builder(view.context).build()
|
||||||
|
exoPlayerView.player = exoPlayer
|
||||||
|
exoPlayer.setMediaItem(MediaItem.fromUri(url))
|
||||||
|
exoPlayer.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchJson(view: View) {
|
||||||
|
val client = OkHttpClient()
|
||||||
|
|
||||||
|
fun run() {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url("https://pipedapi.kavin.rocks/streams/$videoId")
|
||||||
|
.build()
|
||||||
|
client.newCall(request).enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
response.use {
|
||||||
|
if (!response.isSuccessful) throw IOException("Unexpected code $response")
|
||||||
|
val body = response.body!!.string()
|
||||||
|
println(body)
|
||||||
|
val gson = GsonBuilder().create()
|
||||||
|
val videoInPlayer = gson.fromJson(body, VideoInPlayer::class.java)
|
||||||
|
runOnUiThread {
|
||||||
|
initPlayer(view,videoInPlayer.hls)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
run()
|
||||||
|
|
||||||
|
}
|
||||||
|
fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||||
|
this ?: return
|
||||||
|
if (!isAdded) return // Fragment not attached to an Activity
|
||||||
|
activity?.runOnUiThread(action)
|
||||||
|
}
|
||||||
}
|
}
|
49
app/src/main/java/xyz/btcland/libretube/VideoInPlayer.kt
Normal file
49
app/src/main/java/xyz/btcland/libretube/VideoInPlayer.kt
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package xyz.btcland.libretube
|
||||||
|
|
||||||
|
data class VideoInPlayer(
|
||||||
|
val title: String,
|
||||||
|
val description: String,
|
||||||
|
val uploadDate: String,
|
||||||
|
val uploader: String,
|
||||||
|
val uploaderUrl: String,
|
||||||
|
val uploaderAvatar: String,
|
||||||
|
val thumbnailUrl: String,
|
||||||
|
val hls: String,
|
||||||
|
val uploaderVerified: Boolean,
|
||||||
|
val duration: Int,
|
||||||
|
val views: Int,
|
||||||
|
val likes: Int,
|
||||||
|
val dislikes: Int,
|
||||||
|
val relatedStreams: List<Video>,
|
||||||
|
val livestream: Boolean,
|
||||||
|
val proxyUrl: String,
|
||||||
|
val audioStreams: List<Stream>,
|
||||||
|
val videoStreams: List<Stream>,
|
||||||
|
val subtitles: List<Subtitle>
|
||||||
|
|
||||||
|
)
|
||||||
|
data class Stream(
|
||||||
|
val url:String,
|
||||||
|
val format:String,
|
||||||
|
val quality:String,
|
||||||
|
val mimeType:String,
|
||||||
|
val codec:String,
|
||||||
|
val videoOnly: Boolean,
|
||||||
|
val bitrate:Int,
|
||||||
|
val initStart:Int,
|
||||||
|
val initEnd:Int,
|
||||||
|
val indexStart:Int,
|
||||||
|
val indexEnd:Int,
|
||||||
|
val width:Int,
|
||||||
|
val height:Int,
|
||||||
|
val fps:Int
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Subtitle(
|
||||||
|
val url:String,
|
||||||
|
val mimeType:String,
|
||||||
|
val name:String,
|
||||||
|
val code:String,
|
||||||
|
val autoGenerated:Boolean
|
||||||
|
)
|
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<com.google.android.exoplayer2.ui.PlayerView
|
<xyz.btcland.libretube.CustomExoPlayerView
|
||||||
android:id="@+id/player"
|
android:id="@+id/player"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user