Skip to content

Commit

Permalink
Merge pull request #15 from StreamAMG/release/1.2.2
Browse files Browse the repository at this point in the history
SMD-2212 Release Android SDK
  • Loading branch information
StefanoStream authored Jun 2, 2023
2 parents 9b01554 + 768b38c commit bdee321
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Change Log:

All notable changes to this project will be documented in this section.

### 1.2.2 - Improved bitrate and subtitle selector and fixed control resize issue

### 1.2.0 - Subtitle improvements: Default subtitle track auto-selected and get Label caption on subtitle selector

### 1.1.9 - Remove getKS call after successful login and updated validatePurchase to return error when valid token not available
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 21
ext.SDK_VERSION_NAME = "1.2.0"
ext.SDK_VERSION_CODE = 22
ext.SDK_VERSION_NAME = "1.2.2"

publishing {
publications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.streamamg.amg_playkit
import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.hardware.SensorManager
import android.os.Handler
import android.os.Looper
Expand All @@ -11,6 +12,7 @@ import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.OrientationEventListener
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import com.google.gson.JsonObject
Expand Down Expand Up @@ -268,6 +270,12 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface {
}
}

controlsView.addOnLayoutChangeListener(object : OnLayoutChangeListener {
override fun onLayoutChange(v: View?, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
isFullScreen = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
controlsView.hideFullScreenButton(if (isFullScreen) 0 else 1)
}
})
}

private fun checkDefaultCaptionTrack(textTracks: List<MediaTrack>) {
Expand Down Expand Up @@ -1007,16 +1015,12 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface {
orientationActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
mSensorStateChanges = null
mSensorStateChanges = SensorStateChangeActions.WATCH_FOR_PORTAIT_CHANGES
isFullScreen = false
controlsView.hideFullScreenButton(1)
} else if (null != mSensorStateChanges && mSensorStateChanges == SensorStateChangeActions.WATCH_FOR_PORTAIT_CHANGES && (orientation >= 300 && orientation <= 359 || orientation >= 0 && orientation <= 45)) {
mSensorStateChanges = SensorStateChangeActions.SWITCH_FROM_POTRAIT_TO_STANDARD
} else if (null != mSensorStateChanges && mSensorStateChanges == SensorStateChangeActions.SWITCH_FROM_POTRAIT_TO_STANDARD && (orientation <= 300 && orientation >= 240 || orientation <= 130 && orientation >= 60)) {
orientationActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
mSensorStateChanges = null
mSensorStateChanges = SensorStateChangeActions.WATCH_FOR_LANDSCAPE_CHANGES
isFullScreen = true
controlsView.hideFullScreenButton(0)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {
settingsButton.setOnClickListener {
toggleSubtitleSelector(true)
toggleBitrateSelector(bitrateSelectorView.visibility == View.VISIBLE)
refreshViewChildrenLayout(this)
}

subtitleButton.setOnClickListener {
toggleBitrateSelector(true)
toggleSubtitleSelector(subtitleSelectorView.visibility == View.VISIBLE)
refreshViewChildrenLayout(this)
}
}

Expand Down Expand Up @@ -288,6 +290,14 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {
}
}

private fun refreshViewChildrenLayout(view: View) {
view.measure(
MeasureSpec.makeMeasureSpec(view.measuredWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(view.measuredHeight, MeasureSpec.EXACTLY)
)
view.layout(view.left, view.top, view.right, view.bottom)
}

internal fun hideFullScreenButton(orientation: Int) {
if (orientation == 0){
fullScreenButton.setImageResource(minimiseIcon)
Expand Down Expand Up @@ -376,11 +386,13 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {
startTime.append(" / ${timeForDisplay(duration)}", R.color.white_opacity_70)
// endTime.text = timeForDisplay(timeRemaining)

val percentage = position.toFloat() / duration.toFloat()
val lpt = LayoutParams(0, MATCH_PARENT, percentage)
bottomScrubBarTrack.layoutParams = lpt
val lpb = LayoutParams(0, MATCH_PARENT, 1 - percentage)
bottomScrubBarBlank.layoutParams = lpb
if (bottomTrackShouldShow) {
val percentage = position.toFloat() / duration.toFloat()
val lpt = LayoutParams(0, MATCH_PARENT, percentage)
bottomScrubBarTrack.layoutParams = lpt
val lpb = LayoutParams(0, MATCH_PARENT, 1 - percentage)
bottomScrubBarBlank.layoutParams = lpb
}

if (scrubBar.progress < scrubBar.max - 50) {
liveButton.setText(R.string.go_live)
Expand Down Expand Up @@ -472,6 +484,7 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {
if (bottomTrackShouldShow) {
bottomScrubBar.visibility = VISIBLE
}
refreshViewChildrenLayout(this)
}

}
Expand Down Expand Up @@ -503,6 +516,14 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {

fun createSubtitlesSelector(subtitles: List<MediaTrack>) {
subtitleSelectorView.removeAllViews()

if (subtitles.isNullOrEmpty()) {
subtitleButton.visibility = View.GONE
return
} else {
subtitleButton.visibility = View.VISIBLE
}

subtitles.forEachIndexed { index, mediaTrack ->
subtitleSelectorView.addView(listDivider())
subtitleSelectorView.addView(subtitleButton(mediaTrack, index))
Expand Down Expand Up @@ -535,6 +556,7 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {
subtitleSelectorView.visibility = View.GONE
subtitleButton.setBackgroundResource(R.color.transparent)
selectedCaption = index
refreshViewChildrenLayout(this)
}

return btnSubtitle
Expand Down Expand Up @@ -569,10 +591,18 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {

fun createBitrateSelector(bitrates: List<FlavorAsset>? = null) {
bitrateSelectorView.removeAllViews()

if (bitrates.isNullOrEmpty()) {
settingsButton.visibility = View.GONE
return
} else {
settingsButton.visibility = View.VISIBLE
}

bitrateSelectorView.addView(bitrateButton(bitrates?.lastOrNull(), 0, "Auto"))
bitrates?.forEachIndexed { index, bitrate ->
bitrateSelectorView.addView(listDivider())
bitrateSelectorView.addView(bitrateButton(bitrate, index+1, "${bitrate.bitrate}"))
bitrateSelectorView.addView(bitrateButton(bitrate, index+1, "${bitrate.height}p"))
}
}

Expand Down Expand Up @@ -639,6 +669,7 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface {
bitrateSelectorView.visibility = View.GONE
settingsButton.setBackgroundResource(R.color.transparent)
selectedBitrate = index
refreshViewChildrenLayout(this)
}

return btnBitrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ internal fun AMGPlayKit.updateBitrateSelector(callBack: (List<FlavorAsset>?) ->
class MediaContext (
val flavorAssets: List<FlavorAsset>?,
) {
fun fetchBitrates(): List<FlavorAsset>? {

// fun fetchBitrates(): List<Long>? {
// return flavorAssets?.mapNotNull { it.bitrate }?.sorted()
// }
var uniqueAssets: MutableMap<Long, FlavorAsset> = mutableMapOf() // MutableMap to store unique assets by height

fun fetchBitrates(): List<FlavorAsset>? {
return flavorAssets?.sortedBy { it.width }
flavorAssets?.forEach { flavorAsset ->
flavorAsset.height?.let { height ->
if (uniqueAssets.containsKey(height)) {
val exisstingBitrate = uniqueAssets[height]
if (exisstingBitrate?.bitrate ?: 0 < flavorAsset.bitrate ?: 0) {
uniqueAssets[height] = flavorAsset // Replace with higher bitrate asset
}
} else {
uniqueAssets[height] = flavorAsset // Add new unique asset
}
}
}

return uniqueAssets.values.toList().sortedBy { it.bitrate } // Convert MutableMap values to a list and return it sorted
}
}

Expand Down

0 comments on commit bdee321

Please sign in to comment.