mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Merge pull request #499 from Bnyro/master
added support for time stamped links
This commit is contained in:
commit
7dca5153b3
@ -10,6 +10,7 @@ import android.net.Uri
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -199,19 +200,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.replace("/embed/", "")
|
.replace("/embed/", "")
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString("videoId", watch)
|
bundle.putString("videoId", watch)
|
||||||
val frag = PlayerFragment()
|
// for time stamped links
|
||||||
frag.arguments = bundle
|
if (data.query?.contains("t=")!!) {
|
||||||
supportFragmentManager.beginTransaction()
|
val timeStamp = data.query.toString().split("t=")[1]
|
||||||
.remove(PlayerFragment())
|
bundle.putLong("timeStamp", timeStamp.toLong())
|
||||||
.commit()
|
}
|
||||||
supportFragmentManager.beginTransaction()
|
loadWatch(bundle)
|
||||||
.replace(R.id.container, frag)
|
|
||||||
.commitNow()
|
|
||||||
Handler().postDelayed({
|
|
||||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
|
||||||
motionLayout.transitionToEnd()
|
|
||||||
motionLayout.transitionToStart()
|
|
||||||
}, 100)
|
|
||||||
} else if (data.path!!.contains("/watch") && data.query != null) {
|
} else if (data.path!!.contains("/watch") && data.query != null) {
|
||||||
Log.d("dafaq", data.query!!)
|
Log.d("dafaq", data.query!!)
|
||||||
var watch = data.query!!
|
var watch = data.query!!
|
||||||
@ -226,23 +220,26 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
var bundle = Bundle()
|
var bundle = Bundle()
|
||||||
bundle.putString("videoId", watch.replace("v=", ""))
|
bundle.putString("videoId", watch.replace("v=", ""))
|
||||||
var frag = PlayerFragment()
|
// for time stamped links
|
||||||
frag.arguments = bundle
|
if (data.query?.contains("t=")!!) {
|
||||||
supportFragmentManager.beginTransaction()
|
val timeStamp = data.query.toString().split("t=")[1]
|
||||||
.remove(PlayerFragment())
|
bundle.putLong("timeStamp", timeStamp.toLong())
|
||||||
.commit()
|
}
|
||||||
supportFragmentManager.beginTransaction()
|
loadWatch(bundle)
|
||||||
.replace(R.id.container, frag)
|
|
||||||
.commitNow()
|
|
||||||
Handler().postDelayed({
|
|
||||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
|
||||||
motionLayout.transitionToEnd()
|
|
||||||
motionLayout.transitionToStart()
|
|
||||||
}, 100)
|
|
||||||
} else {
|
} else {
|
||||||
var watch = data.path!!.replace("/", "")
|
var watch = data.path!!.replace("/", "")
|
||||||
var bundle = Bundle()
|
var bundle = Bundle()
|
||||||
bundle.putString("videoId", watch)
|
bundle.putString("videoId", watch)
|
||||||
|
// for time stamped links
|
||||||
|
if (data.query?.contains("t=")!!) {
|
||||||
|
val timeStamp = data.query.toString().split("t=")[1]
|
||||||
|
bundle.putLong("timeStamp", timeStamp.toLong())
|
||||||
|
}
|
||||||
|
loadWatch(bundle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadWatch(bundle: Bundle) {
|
||||||
var frag = PlayerFragment()
|
var frag = PlayerFragment()
|
||||||
frag.arguments = bundle
|
frag.arguments = bundle
|
||||||
supportFragmentManager.beginTransaction()
|
supportFragmentManager.beginTransaction()
|
||||||
@ -251,13 +248,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
supportFragmentManager.beginTransaction()
|
supportFragmentManager.beginTransaction()
|
||||||
.replace(R.id.container, frag)
|
.replace(R.id.container, frag)
|
||||||
.commitNow()
|
.commitNow()
|
||||||
Handler().postDelayed({
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
|
||||||
motionLayout.transitionToEnd()
|
motionLayout.transitionToEnd()
|
||||||
motionLayout.transitionToStart()
|
motionLayout.transitionToStart()
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
try {
|
try {
|
||||||
|
@ -435,9 +435,15 @@ class PlayerFragment : Fragment() {
|
|||||||
prepareExoPlayerView()
|
prepareExoPlayerView()
|
||||||
if (response.chapters != null) initializeChapters(response.chapters)
|
if (response.chapters != null) initializeChapters(response.chapters)
|
||||||
setResolutionAndSubtitles(view, response)
|
setResolutionAndSubtitles(view, response)
|
||||||
|
// support for time stamped links
|
||||||
|
if (arguments?.getLong("timeStamp") != null) {
|
||||||
|
val position = arguments?.getLong("timeStamp")!! * 1000
|
||||||
|
exoPlayer.seekTo(position)
|
||||||
|
}
|
||||||
exoPlayer.prepare()
|
exoPlayer.prepare()
|
||||||
exoPlayer.play()
|
exoPlayer.play()
|
||||||
initializePlayerView(view, response)
|
initializePlayerView(view, response)
|
||||||
|
initializePlayerNotification(requireContext())
|
||||||
if (!relatedStreamsEnabled) toggleComments()
|
if (!relatedStreamsEnabled) toggleComments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -843,8 +849,6 @@ class PlayerFragment : Fragment() {
|
|||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
val playbackSpeed = sharedPreferences.getString("playback_speed", "1F")?.toFloat()
|
val playbackSpeed = sharedPreferences.getString("playback_speed", "1F")?.toFloat()
|
||||||
exoPlayer.setPlaybackSpeed(playbackSpeed!!)
|
exoPlayer.setPlaybackSpeed(playbackSpeed!!)
|
||||||
|
|
||||||
initializePlayerNotification(requireContext())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializePlayerNotification(c: Context) {
|
private fun initializePlayerNotification(c: Context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user