-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPlayerActivity.kt
More file actions
123 lines (111 loc) · 4.95 KB
/
PlayerActivity.kt
File metadata and controls
123 lines (111 loc) · 4.95 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.theoplayer.sample.playback.basic
import android.util.Log
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.theoplayer.android.api.THEOplayerConfig
import com.theoplayer.android.api.THEOplayerGlobal
import com.theoplayer.android.api.THEOplayerView
import com.theoplayer.android.api.event.player.ErrorEvent
import com.theoplayer.android.api.event.player.PlayerEventTypes
import com.theoplayer.android.ui.DefaultUI
import com.theoplayer.android.ui.rememberPlayer
import com.theoplayer.android.ui.theme.THEOplayerTheme
import com.theoplayer.sample.common.AppTopBar
import com.theoplayer.sample.common.SourceManager
class PlayerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Enable all debug logs from THEOplayer.
THEOplayerGlobal.getSharedInstance(this).logger.enableAllTags()
super.onCreate(savedInstanceState)
setContent {
val context = LocalContext.current
val theoplayerView = remember(context) {
// Creating the player with default parameters.
THEOplayerView(context, THEOplayerConfig.Builder().build()).apply {
// Keep the device screen on.
keepScreenOn = true
}
}
val player = rememberPlayer(theoplayerView)
val theoPlayer = theoplayerView.player
LaunchedEffect(player) {
// Configuring the player with a SourceDescription object.
theoPlayer.source = SourceManager.BIP_BOP_HLS
// Set autoplay to start video whenever player is visible.
theoPlayer.isAutoplay = true
// Attach event listeners.
theoPlayer.addEventListener(PlayerEventTypes.SOURCECHANGE) {
Log.i(TAG, "Event: SOURCECHANGE")
}
theoPlayer.addEventListener(PlayerEventTypes.CURRENTSOURCECHANGE) {
Log.i(TAG, "Event: CURRENTSOURCECHANGE")
}
theoPlayer.addEventListener(PlayerEventTypes.LOADEDDATA) {
Log.i(TAG, "Event: LOADEDDATA")
}
theoPlayer.addEventListener(PlayerEventTypes.LOADEDMETADATA) {
Log.i(TAG, "Event: LOADEDMETADATA")
}
theoPlayer.addEventListener(PlayerEventTypes.DURATIONCHANGE) {
Log.i(TAG, "Event: DURATIONCHANGE")
}
theoPlayer.addEventListener(PlayerEventTypes.TIMEUPDATE) {
// Log.i(TAG, "Event: TIMEUPDATE")
}
theoPlayer.addEventListener(PlayerEventTypes.PLAY) {
Log.i(TAG, "Event: PLAY")
}
theoPlayer.addEventListener(PlayerEventTypes.PLAYING) {
Log.i(TAG, "Event: PLAYING")
}
theoPlayer.addEventListener(PlayerEventTypes.PAUSE) {
Log.i(TAG, "Event: PAUSE")
}
theoPlayer.addEventListener(PlayerEventTypes.SEEKING) {
Log.i(TAG, "Event: SEEKING")
}
theoPlayer.addEventListener(PlayerEventTypes.SEEKED) {
Log.i(TAG, "Event: SEEKED")
}
theoPlayer.addEventListener(PlayerEventTypes.WAITING) {
Log.i(TAG, "Event: WAITING")
}
theoPlayer.addEventListener(PlayerEventTypes.READYSTATECHANGE) {
Log.i(TAG, "Event: READYSTATECHANGE")
}
theoPlayer.addEventListener(PlayerEventTypes.PRESENTATIONMODECHANGE) {
Log.i(TAG, "Event: PRESENTATIONMODECHANGE")
}
theoPlayer.addEventListener(PlayerEventTypes.VOLUMECHANGE) {
Log.i(TAG, "Event: VOLUMECHANGE")
}
theoPlayer.addEventListener(PlayerEventTypes.ERROR) { event: ErrorEvent ->
Log.i(TAG, "Event: ERROR, error=" + event.errorObject)
}
}
THEOplayerTheme(useDarkTheme = true) {
Scaffold(
topBar = { AppTopBar() }
) { padding ->
DefaultUI(
modifier = Modifier
.padding(padding)
.fillMaxSize(),
player = player
)
}
}
}
}
companion object {
private val TAG: String = PlayerActivity::class.java.simpleName
}
}