From e37c3c0db6a1c92d298a413ab3e055af30410741 Mon Sep 17 00:00:00 2001 From: Stefano Russello Date: Thu, 19 May 2022 12:54:28 +0200 Subject: [PATCH] SMD-689 SMD-691 Chromecast and bitrate fix SMD-689 Fixed crash when chromecasting offline SMD-691 Fixed crash when bitrate selector receives empty list --- PlayKitReadMe.md | 4 ++++ README.md | 2 ++ build.gradle | 4 ++-- .../com/streamamg/amg_playkit/AMGPlayKit.kt | 22 ++++++++++++++----- .../controls/AMGPlayKitStandardControl.kt | 10 ++++----- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/PlayKitReadMe.md b/PlayKitReadMe.md index 99ce982..7516541 100644 --- a/PlayKitReadMe.md +++ b/PlayKitReadMe.md @@ -599,6 +599,10 @@ PlayKit will atttempt to change bitrate to that value (or the closest one BELOW All notable changes to this project will be documented in this section. +### 1.1.2 +- Fixed chromecasting crash when offline +- Fixed bitrate selector crash when empty list + ### 1.1.1 - Added startPosition to loadMedia - Fixed bitrate selector icon when live diff --git a/README.md b/README.md index 1f7c41e..0906a2a 100755 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ Change Log: All notable changes to this project will be documented in this section. +### 1.1.2 - Fixed bitrate and offline issues + ### 1.1.1 - PlayKit minor update ### 1.1.0 - Improved bitrate selector UI and Playkit updates diff --git a/build.gradle b/build.gradle index 222f22c..747ad01 100644 --- a/build.gradle +++ b/build.gradle @@ -15,8 +15,8 @@ plugins { id 'maven-publish' } // Versions of the library modules are matched (eg 1.0 core goes with 1.0 cloudmatrix) to prevent dependency issues -ext.SDK_VERSION_CODE = 12 -ext.SDK_VERSION_NAME = "1.1.1" +ext.SDK_VERSION_CODE = 13 +ext.SDK_VERSION_NAME = "1.1.2" publishing { publications { diff --git a/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/AMGPlayKit.kt b/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/AMGPlayKit.kt index ab628c3..b7b80a4 100644 --- a/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/AMGPlayKit.kt +++ b/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/AMGPlayKit.kt @@ -7,6 +7,7 @@ import android.hardware.SensorManager import android.os.Handler import android.os.Looper import android.util.AttributeSet +import android.util.Log import android.util.TypedValue import android.view.LayoutInflater import android.view.OrientationEventListener @@ -39,10 +40,10 @@ import com.streamamg.amg_playkit.playkitExtensions.FlavorAsset import com.streamamg.amg_playkit.playkitExtensions.isLive import com.streamamg.amg_playkit.playkitExtensions.setBitrate import com.streamamg.amg_playkit.playkitExtensions.updateBitrateSelector -import okhttp3.OkHttpClient -import okhttp3.Request +import okhttp3.* import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import java.io.IOException import java.net.URL import java.util.* import kotlin.collections.ArrayList @@ -346,9 +347,16 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface { .get() .build() thread { - val response = client.newCall(request).execute() - val responseBody = response.request.url.toString() - sendCastingURL(responseBody) + client.newCall(request).enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { + Log.e(this@AMGPlayKit.javaClass.simpleName, e.localizedMessage) + } + + override fun onResponse(call: Call, response: Response) { + val responseBody = response.request.url.toString() + sendCastingURL(responseBody) + } + }) } } @@ -490,7 +498,9 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface { updateAnalyticsPlugin(mediaConfig.entryID) player?.prepare(mediaConfig.mediaConfig) - updateBitrateSelector() + if (bitrateSelector) { + updateBitrateSelector() + } controlsView.setMediaType(mediaType) if (mediaType == AMGMediaType.VOD){ diff --git a/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/controls/AMGPlayKitStandardControl.kt b/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/controls/AMGPlayKitStandardControl.kt index 9454eef..53f1329 100644 --- a/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/controls/AMGPlayKitStandardControl.kt +++ b/streamamg-sdk-playkit/src/main/java/com/streamamg/amg_playkit/controls/AMGPlayKitStandardControl.kt @@ -467,12 +467,10 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface { fun createBitrateSelector(bitrates: List? = null) { bitrateSelectorView.removeAllViews() - bitrateSelectorView.addView(bitrateButton(bitrates?.last(), 0, "Auto")) - if (bitrates != null) { - bitrates.forEachIndexed { index, bitrate -> - bitrateSelectorView.addView(bitrateDivider()) - bitrateSelectorView.addView(bitrateButton(bitrate, index+1, "${bitrate.bitrate}")) - } + bitrateSelectorView.addView(bitrateButton(bitrates?.lastOrNull(), 0, "Auto")) + bitrates?.forEachIndexed { index, bitrate -> + bitrateSelectorView.addView(bitrateDivider()) + bitrateSelectorView.addView(bitrateButton(bitrate, index+1, "${bitrate.bitrate}")) } }