Add fullscreen to exoplayer
This commit is contained in:
parent
1f90e21f68
commit
e022fe5e96
|
@ -5,6 +5,7 @@ import android.content.Intent
|
|||
import android.content.pm.ActivityInfo
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.Image
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
|
@ -14,6 +15,7 @@ import android.view.WindowManager
|
|||
import android.webkit.WebChromeClient
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.media3.common.MediaItem
|
||||
|
@ -43,11 +45,20 @@ class ReproductorActivity : AppCompatActivity() {
|
|||
private lateinit var viewAdapter: RecyclerView.Adapter<*>
|
||||
private lateinit var viewManager: RecyclerView.LayoutManager
|
||||
|
||||
// Exoplayer
|
||||
private lateinit var player: ExoPlayer
|
||||
|
||||
// Fullscreen info
|
||||
private var isFullscreen = false
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled", "SetTextI18n")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_reproductor)
|
||||
|
||||
val fullscreenButton: ImageView = exoPlayer.findViewById(R.id.exo_fullscreen_custom)
|
||||
val fullscreenButton2 = fullscreenPlayer.findViewById<ImageView>(R.id.exo_fullscreen_custom)
|
||||
|
||||
videoView.webChromeClient = WebClient()
|
||||
videoView.settings.javaScriptEnabled = true
|
||||
videoView.settings.allowContentAccess = true
|
||||
|
@ -91,6 +102,8 @@ class ReproductorActivity : AppCompatActivity() {
|
|||
showMoreBtn.setOnClickListener { getDescription() }
|
||||
shareLayout.setOnClickListener { shareIntent() }
|
||||
reportLayout.setOnClickListener { reportIntent() }
|
||||
fullscreenButton.setOnClickListener { toggleFullscreen() }
|
||||
fullscreenButton2.setOnClickListener { toggleFullscreen() }
|
||||
|
||||
userImg.setOnClickListener {
|
||||
val intent = Intent(this, ChannelActivity::class.java)
|
||||
|
@ -103,7 +116,7 @@ class ReproductorActivity : AppCompatActivity() {
|
|||
val video = this.clientVideo.getVideo(this.video.uuid)
|
||||
runOnUiThread {
|
||||
try {
|
||||
val player = ExoPlayer.Builder(this.baseContext).build()
|
||||
player = ExoPlayer.Builder(this.baseContext).build()
|
||||
exoPlayer.player = player
|
||||
|
||||
println("----- video --------")
|
||||
|
@ -114,7 +127,7 @@ class ReproductorActivity : AppCompatActivity() {
|
|||
// Prepare the player.
|
||||
player.prepare()
|
||||
// Start the playback.
|
||||
player.play()
|
||||
// player.play()
|
||||
} catch(err: Exception) {
|
||||
err.printStackTrace()
|
||||
}
|
||||
|
@ -332,6 +345,43 @@ class ReproductorActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun toggleFullscreen () {
|
||||
if (isFullscreen) {
|
||||
nonFullScreen.visibility = View.VISIBLE
|
||||
fullScreenExo.visibility = View.GONE
|
||||
exoPlayer.player = player
|
||||
fullscreenPlayer.player = null
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
|
||||
val attrs = window.attributes
|
||||
attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN.inv()
|
||||
attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON.inv()
|
||||
window.attributes = attrs
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
|
||||
isFullscreen = false
|
||||
}
|
||||
else {
|
||||
val matchParent = WindowManager.LayoutParams.MATCH_PARENT
|
||||
|
||||
nonFullScreen.visibility = View.GONE
|
||||
fullScreenExo.visibility = View.VISIBLE
|
||||
|
||||
exoPlayer.player = null
|
||||
fullscreenPlayer.player = player
|
||||
|
||||
setFullscreen(window)
|
||||
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||
isFullscreen = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
player.release()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
internal inner class WebClient: WebChromeClient() {
|
||||
private var mCustomView: View? = null
|
||||
private var mCustomViewCallback: WebChromeClient.CustomViewCallback? = null
|
||||
|
|
|
@ -7,7 +7,7 @@ fun mapSeconds (inputSeconds: Int): String {
|
|||
|
||||
if (minutes > 60) {
|
||||
hours = minutes / 60
|
||||
minutes = minutes % 60
|
||||
minutes %= 60
|
||||
}
|
||||
|
||||
var result = minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0')
|
||||
|
|
|
@ -69,6 +69,26 @@ class VideoModel(
|
|||
}
|
||||
data.endArray()
|
||||
}
|
||||
"files" -> {
|
||||
if (streamingData === null) {
|
||||
data.beginArray()
|
||||
if (data.hasNext()) {
|
||||
data.beginObject()
|
||||
while (data.hasNext()) {
|
||||
val key2 = data.nextName()
|
||||
when (key2.toString()) {
|
||||
"fileDownloadUrl"->{
|
||||
streamingData = StreamingModel()
|
||||
streamingData!!.playlistUrl = data.nextString()
|
||||
}
|
||||
else -> data.skipValue()
|
||||
}
|
||||
}
|
||||
data.endObject()
|
||||
}
|
||||
data.endArray()
|
||||
}
|
||||
}
|
||||
"channel"->{
|
||||
data.beginObject()
|
||||
while (data.hasNext()){
|
||||
|
|
|
@ -10,11 +10,39 @@
|
|||
android:id="@+id/fullScreen"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:visibility="gone" />
|
||||
android:layout_alignParentBottom="true"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/fullScreenExo"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" >
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/fullscreenPlayer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#000"
|
||||
app:use_controller="true"
|
||||
app:controller_layout_id="@layout/custom_player_controls"
|
||||
app:player_layout_id="@layout/exo_player_view"/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/nonFullScreen"
|
||||
|
@ -38,7 +66,8 @@
|
|||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="222dp"
|
||||
android:layout_weight="1" />
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone" />
|
||||
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/exoPlayer"
|
||||
|
|
|
@ -84,20 +84,12 @@
|
|||
android:layout_weight="2" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/exo_fullscreen"
|
||||
android:id="@+id/exo_fullscreen_custom"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:src="@drawable/ic_fullscreen_24"
|
||||
android:layout_weight="0"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/exo_fullscreen2"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0"
|
||||
android:src="@drawable/ic_fullscreen_24" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<ImageView
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="230dp"
|
||||
android:layout_height="222dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
Loading…
Reference in New Issue