-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPlayerActivity.kt
More file actions
139 lines (127 loc) · 5.81 KB
/
Copy pathPlayerActivity.kt
File metadata and controls
139 lines (127 loc) · 5.81 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
package com.theoplayer.sample.drm_playback
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.contentprotection.KeySystemId
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
import com.theoplayer.sample.drm_playback.integration.axinom.AxinomWidevineContentProtectionIntegrationFactory
class PlayerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Register the DRM integration to the global THEOplayer object.
THEOplayerGlobal.getSharedInstance(this).registerContentProtectionIntegration(
"axinom",
KeySystemId.WIDEVINE,
AxinomWidevineContentProtectionIntegrationFactory()
)
// 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) {
// Configuring the player with a DRM-protected SourceDescription.
theoPlayer.source = SourceManager.CUSTOM_AXINOM_DRM
// 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.ENDED) {
Log.i(TAG, "Event: ENDED")
}
theoPlayer.addEventListener(PlayerEventTypes.ERROR) { event: ErrorEvent ->
Log.i(TAG, "Event: ERROR, error=" + event.errorObject)
}
// DRM-specific event listeners.
theoPlayer.addEventListener(PlayerEventTypes.CONTENTPROTECTIONSUCCESS) {
Log.i(TAG, "Event: CONTENTPROTECTIONSUCCESS")
}
theoPlayer.addEventListener(PlayerEventTypes.CONTENTPROTECTIONERROR) {
Log.i(TAG, "Event: CONTENTPROTECTIONERROR")
}
}
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
}
}