-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlayerActivity.kt
104 lines (84 loc) · 3.92 KB
/
PlayerActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.theoplayer.sample.surface
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.theoplayer.android.api.player.AspectRatio
import com.theoplayer.android.api.player.Player
import com.theoplayer.android.api.player.RenderingTarget
import com.theoplayer.sample.common.SourceManager
import com.theoplayer.sample.surface.databinding.ActivityPlayerBinding
class PlayerActivity : AppCompatActivity() {
private lateinit var viewBinding: ActivityPlayerBinding
private lateinit var theoPlayer: Player
private var aspectRatio = AspectRatio.FIT
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// See basic-playback's PlayerActivity for more information about basic setup.
viewBinding = DataBindingUtil.setContentView(this, R.layout.activity_player)
theoPlayer = viewBinding.theoPlayerView.player
setSupportActionBar(viewBinding.toolbar)
viewBinding.theoPlayerView.fullScreenManager.isFullScreenOrientationCoupled = true
theoPlayer.source = SourceManager.ELEPHANTS_DREAM_HLS
theoPlayer.isAutoplay = true
theoPlayer.setAspectRatio(aspectRatio)
// Set onClickListeners to allow surface switching.
viewBinding.btnSetSurfaceView.setOnClickListener(::setSurfaceView)
viewBinding.btnSetTextureView.setOnClickListener(::setTextureView)
viewBinding.btnSetCustomSurfaceView.setOnClickListener(::setCustomSurfaceView)
viewBinding.btnSetCustomTextureView.setOnClickListener(::setCustomTextureView)
}
private fun setSurfaceView(view: View) {
viewBinding.customSurfaceViewContainer.removeAllViews()
viewBinding.customTextureViewContainer.removeAllViews()
// Set the rendering target to SurfaceView provided by THEOplayer
theoPlayer.setRenderingTarget(RenderingTarget.SURFACE_VIEW)
}
private fun setTextureView(view: View) {
viewBinding.customSurfaceViewContainer.removeAllViews()
viewBinding.customTextureViewContainer.removeAllViews()
// Set the rendering target to TextureView provided by THEOplayer
theoPlayer.setRenderingTarget(RenderingTarget.TEXTURE_VIEW)
}
private fun setCustomSurfaceView(view: View) {
viewBinding.customSurfaceViewContainer.removeAllViews()
viewBinding.customTextureViewContainer.removeAllViews()
val layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
layoutParams.gravity = Gravity.CENTER
val customSurfaceView = CustomSurfaceView(this, theoPlayer, aspectRatio)
customSurfaceView.layoutParams = layoutParams
viewBinding.customSurfaceViewContainer.addView(customSurfaceView)
}
private fun setCustomTextureView(view: View) {
viewBinding.customSurfaceViewContainer.removeAllViews()
viewBinding.customTextureViewContainer.removeAllViews()
val layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
layoutParams.gravity = Gravity.CENTER
val customTextureView = CustomTextureView(this, theoPlayer, aspectRatio)
customTextureView.layoutParams = layoutParams
viewBinding.customTextureViewContainer.addView(customTextureView)
}
override fun onPause() {
super.onPause()
viewBinding.theoPlayerView.onPause()
}
override fun onResume() {
super.onResume()
viewBinding.theoPlayerView.onResume()
}
override fun onDestroy() {
super.onDestroy()
viewBinding.theoPlayerView.onDestroy()
}
companion object {
private val TAG: String = PlayerActivity::class.java.simpleName
}
}