-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from THEOplayer/feature/uplink-preplay-events
Uplynk connector: Preplay events
- Loading branch information
Showing
17 changed files
with
593 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
connectors/uplynk/src/main/java/com/theoplayer/android/connector/uplynk/UplynkListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.theoplayer.android.connector.uplynk | ||
|
||
import com.theoplayer.android.connector.uplynk.network.AssetInfoResponse | ||
import com.theoplayer.android.connector.uplynk.network.PreplayResponse | ||
|
||
/** | ||
* A listener interface for receiving events related to Uplynk | ||
* Implementations of this interface can be used to handle responses from Uplynk's API. | ||
*/ | ||
interface UplynkListener { | ||
|
||
/** | ||
* Called when a preplay response is received from Uplynk. | ||
* | ||
* For more details, refer to the [Preplay API (Version 2) Documentation](https://docs.edgecast.com/video/index.html#Develop/Preplayv2.htm). | ||
* | ||
* @param response the `PreplayResponse` object containing information relevant to the preplay request. | ||
*/ | ||
fun onPreplayResponse(response: PreplayResponse) {} | ||
|
||
/** | ||
* Called when a preplay response is received from Uplynk and failed to be parsed | ||
* | ||
* @param exception the `Exception` occurred during the response parsing | ||
*/ | ||
fun onPreplayFailure(exception: Exception) {} | ||
|
||
/** | ||
* Called when an asset information response is received from Uplynk. | ||
* | ||
* For more details, refer to the [Asset Info Documentation](https://docs.edgecast.com/video/index.html#Develop/AssetInfo.htm). | ||
* | ||
* @param response the `AssetInfoResponse` object containing detailed information about the asset. | ||
*/ | ||
fun onAssetInfoResponse(response: AssetInfoResponse) {} | ||
|
||
/** | ||
* Called when an asset information response is failed | ||
* | ||
* @param exception the `Exception` occurred during the request | ||
*/ | ||
fun onAssetInfoFailure(exception: Exception) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...k/src/main/java/com/theoplayer/android/connector/uplynk/internal/UplynkEventDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.theoplayer.android.connector.uplynk.internal | ||
|
||
import android.os.Handler | ||
import android.os.Looper | ||
import com.theoplayer.android.connector.uplynk.UplynkListener | ||
import com.theoplayer.android.connector.uplynk.network.AssetInfoResponse | ||
import com.theoplayer.android.connector.uplynk.network.PreplayResponse | ||
import java.util.concurrent.CopyOnWriteArrayList | ||
|
||
internal class UplynkEventDispatcher { | ||
private val handler = Handler(Looper.getMainLooper()) | ||
|
||
private val listeners = CopyOnWriteArrayList<UplynkListener>() | ||
|
||
fun dispatchPreplayEvents(response: PreplayResponse) = handler.post { | ||
listeners.forEach { it.onPreplayResponse(response) } | ||
} | ||
|
||
fun dispatchAssetInfoEvents(assetInfo: AssetInfoResponse) = handler.post { | ||
listeners.forEach { it.onAssetInfoResponse(assetInfo) } | ||
} | ||
|
||
fun dispatchAssetInfoFailure(e: Exception) = handler.post { | ||
listeners.forEach { it.onAssetInfoFailure(e) } | ||
} | ||
|
||
fun dispatchPreplayFailure(e: Exception) = handler.post { | ||
listeners.forEach { it.onPreplayFailure(e) } | ||
} | ||
|
||
fun addListener(listener: UplynkListener) = listeners.add(listener) | ||
|
||
fun removeListener(listener: UplynkListener) = listeners.remove(listener) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../java/com/theoplayer/android/connector/uplynk/internal/network/PreplayInternalResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.theoplayer.android.connector.uplynk.internal.network | ||
|
||
import com.theoplayer.android.connector.uplynk.network.PreplayResponse | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.Json | ||
|
||
|
||
@Serializable | ||
internal data class MinimalPreplayResponse( | ||
|
||
/** | ||
* The manifest's URL. (**NonNull**) | ||
*/ | ||
val playURL: String, | ||
|
||
/** | ||
* The identifier of the viewer's session. (**NonNull**) | ||
*/ | ||
val sid: String) | ||
|
||
|
||
internal class PreplayInternalResponse(val body: String, private val json: Json) { | ||
fun parseMinimalResponse(): MinimalPreplayResponse = json.decodeFromString(body) | ||
fun parseExternalResponse(): PreplayResponse = json.decodeFromString(body) | ||
} |
20 changes: 20 additions & 0 deletions
20
...plynk/src/main/java/com/theoplayer/android/connector/uplynk/internal/network/UplynkApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.theoplayer.android.connector.uplynk.internal.network | ||
|
||
import com.theoplayer.android.connector.uplynk.network.AssetInfoResponse | ||
import kotlinx.serialization.json.Json | ||
|
||
|
||
internal class UplynkApi { | ||
private val json = Json { ignoreUnknownKeys = true } | ||
private val network = HttpsConnection() | ||
|
||
suspend fun preplay(srcURL: String): PreplayInternalResponse { | ||
val body = network.get(srcURL) | ||
return PreplayInternalResponse(body, json) | ||
} | ||
|
||
suspend fun assetInfo(url: String): AssetInfoResponse { | ||
val body = network.get(url) | ||
return json.decodeFromString(body) | ||
} | ||
} |
Oops, something went wrong.