-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPlayerActivity.kt
More file actions
170 lines (157 loc) · 7.36 KB
/
Copy pathPlayerActivity.kt
File metadata and controls
170 lines (157 loc) · 7.36 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.theoplayer.sample.ads.googleima
import android.os.Bundle
import android.util.Log
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.ads.AdsEventTypes
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) {
THEOplayerView(context, THEOplayerConfig.Builder().build()).apply {
keepScreenOn = true
}
}
val player = rememberPlayer(theoplayerView)
val theoPlayer = theoplayerView.player
LaunchedEffect(player) {
// Coupling the orientation of the device with the fullscreen state.
theoplayerView.fullScreenManager.isFullScreenOrientationCoupled = true
// THEOplayer automatically adds all available integrations to the player.
// Alternatively, you can set autoIntegrations(false) on your player configuration
// and add them manually.
// val googleImaIntegration = GoogleImaIntegrationFactory.createGoogleImaIntegration(theoplayerView)
// theoPlayer.addIntegration(googleImaIntegration)
// Set a source with ads on the player.
theoPlayer.source = SourceManager.HLS_WITH_VMAP
// Set autoplay to start video whenever player is visible.
theoPlayer.isAutoplay = true
// Attach player 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.ENDED) {
Log.i(TAG, "Event: ENDED")
}
theoPlayer.addEventListener(PlayerEventTypes.ERROR) { event: ErrorEvent ->
Log.i(TAG, "Event: ERROR, error=" + event.errorObject)
}
// Attach ad event listeners.
theoPlayer.ads.addEventListener(AdsEventTypes.AD_BEGIN) {
Log.i(TAG, "Event: AD_BEGIN")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_END) {
Log.i(TAG, "Event: AD_END")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_ERROR) {
Log.i(TAG, "Event: AD_ERROR")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_LOADED) {
Log.i(TAG, "Event: AD_LOADED")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_BREAK_BEGIN) {
Log.i(TAG, "Event: AD_BREAK_BEGIN")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_BREAK_END) {
Log.i(TAG, "Event: AD_BREAK_END")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_SKIP) {
Log.i(TAG, "Event: AD_SKIP")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_TAPPED) {
Log.i(TAG, "Event: AD_TAPPED")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_IMPRESSION) {
Log.i(TAG, "Event: AD_IMPRESSION")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_FIRST_QUARTILE) {
Log.i(TAG, "Event: AD_FIRST_QUARTILE")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_MIDPOINT) {
Log.i(TAG, "Event: AD_MIDPOINT")
}
theoPlayer.ads.addEventListener(AdsEventTypes.AD_THIRD_QUARTILE) {
Log.i(TAG, "Event: AD_THIRD_QUARTILE")
}
}
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
}
}