@@ -10,12 +10,12 @@ import kotlin.collections.HashMap
1010
1111
1212open class MediaEvent (
13- session : MediaSession ,
13+ private val session : MediaSession ,
1414 val eventName : String = " Unknown" ,
1515 val timeStamp : Long = System .currentTimeMillis(),
1616 val id : String = UUID .randomUUID().toString(),
1717 val options : Options ? = null
18- ): BaseEvent(Type .MEDIA ) {
18+ ) : BaseEvent(Type .MEDIA ) {
1919
2020 var sessionId: String? = null
2121 var mediaContent: MediaContent
@@ -51,11 +51,11 @@ open class MediaEvent(
5151 }
5252 }
5353 }
54-
54+
5555 fun toMPEvent (): MPEvent {
5656 val mediaAttributes = getSessionAttributes()
5757 mediaAttributes.putAll(getEventAttributes())
58- mediaAttributes.putAll(customAttributeStrings? : mapOf ())
58+ mediaAttributes.putAll(customAttributeStrings ? : mapOf ())
5959 return MPEvent .Builder (eventName, MParticle .EventType .Media )
6060 .customAttributes(mediaAttributes)
6161 .build()
@@ -64,6 +64,9 @@ open class MediaEvent(
6464 internal fun getSessionAttributes (): MutableMap <String , Any ?> {
6565 val sessionAttributes = HashMap <String , Any ?>()
6666 sessionAttributes.putIfNotNull(MediaAttributeKeys .MEDIA_SESSION_ID , sessionId)
67+ session.mediaSessionAttributes.forEach {
68+ sessionAttributes.putIfNotNull(it.key, it.value)
69+ }
6770
6871 sessionAttributes.putIfNotNull(MediaAttributeKeys .PLAYHEAD_POSITION , playheadPosition)
6972 sessionAttributes.putIfNotNull(MediaAttributeKeys .TITLE , mediaContent.name)
@@ -140,41 +143,51 @@ open class MediaEvent(
140143 json.put(" buffer position" , it)
141144 }
142145 qos?.apply {
143- json.put(" qos" , JSONObject ()
144- .put(" bit rate" , bitRate)
145- .put(" dropped frames" , droppedFrames)
146- .put(" fps" , fps)
147- .put(" startup time" , startupTime))
148- }
149- mediaAd?.apply {
150- json.put(" media ad" , JSONObject ()
151- .put(" title" , title)
152- .put(" id" , id)
153- .put(" advertiser" , advertiser)
154- .put(" campaign" , campaign)
155- .put(" creative" , creative)
156- .put(" siteId" , siteId)
157- .put(" duration" , duration)
158- .put(" placement" , placement))
146+ json.put(
147+ " qos" , JSONObject ()
148+ .put(" bit rate" , bitRate)
149+ .put(" dropped frames" , droppedFrames)
150+ .put(" fps" , fps)
151+ .put(" startup time" , startupTime)
152+ )
153+ }
154+ mediaAd?.apply {
155+ json.put(
156+ " media ad" , JSONObject ()
157+ .put(" title" , title)
158+ .put(" id" , id)
159+ .put(" advertiser" , advertiser)
160+ .put(" campaign" , campaign)
161+ .put(" creative" , creative)
162+ .put(" siteId" , siteId)
163+ .put(" duration" , duration)
164+ .put(" placement" , placement)
165+ )
159166 .put(" position" , position)
160167 }
161168 segment?.apply {
162- json.put(" segment" , JSONObject ()
163- .put(" title" , title)
164- .put(" index" , index)
165- .put(" duration" , duration))
169+ json.put(
170+ " segment" , JSONObject ()
171+ .put(" title" , title)
172+ .put(" index" , index)
173+ .put(" duration" , duration)
174+ )
166175 }
167176 adBreak?.apply {
168- json.put(" adBreak" , JSONObject ()
169- .put(" title" , title)
170- .put(" duration" , duration))
171- }
172- json.put(" Media Content" , JSONObject ()
173- .put(" name" , mediaContent.name)
174- .put(" id" , mediaContent.contentId)
175- .put(" duration" , mediaContent.duration)
176- .put(" stream type" , mediaContent.streamType)
177- .put(" content type" , mediaContent.contentType))
177+ json.put(
178+ " adBreak" , JSONObject ()
179+ .put(" title" , title)
180+ .put(" duration" , duration)
181+ )
182+ }
183+ json.put(
184+ " Media Content" , JSONObject ()
185+ .put(" name" , mediaContent.name)
186+ .put(" id" , mediaContent.contentId)
187+ .put(" duration" , mediaContent.duration)
188+ .put(" stream type" , mediaContent.streamType)
189+ .put(" content type" , mediaContent.contentType)
190+ )
178191
179192 json.put(" session id" , sessionId)
180193 json.put(" timestamp" , timeStamp)
@@ -186,7 +199,7 @@ open class MediaEvent(
186199 }
187200 return json.toString()
188201 }
189-
202+
190203 fun <T > HashMap <String , T >.putIfNotNull (key : String , value : T ? ) {
191204 value?.also {
192205 put(key, it)
0 commit comments