From f537b288665ffe13c1751dbd4ba3a53fe85d6dff Mon Sep 17 00:00:00 2001 From: Stefano Russello Date: Tue, 11 Apr 2023 11:17:48 +0200 Subject: [PATCH] SMD-2016 Release Android SDK SMD-1958 Subtitle improvements --- AuthenticationReadMe.md | 2 +- Changelog.md | 2 + PlayKitReadMe.md | 12 ++++- README.md | 5 ++ build.gradle | 4 +- .../com/streamamg/amg_playkit/AMGPlayKit.kt | 54 ++++++++++++++++--- .../controls/AMGPlayKitStandardControl.kt | 25 ++++++--- .../interfaces/AMGPlayerInterface.kt | 2 +- .../streamamg/amg_playkit/models/MediaItem.kt | 6 ++- .../streamamg_sdk_purchases/AMGPurchases.kt | 1 + 10 files changed, 89 insertions(+), 24 deletions(-) diff --git a/AuthenticationReadMe.md b/AuthenticationReadMe.md index 6643077..8775f7e 100644 --- a/AuthenticationReadMe.md +++ b/AuthenticationReadMe.md @@ -130,7 +130,7 @@ Change Log: All notable changes to this project will be documented in this section. -### 1.1.9-SNAPSHOT - Remove getKS call after successful login +### 1.1.9 - Remove getKS call after successful login ### 1.0.1 - Release diff --git a/Changelog.md b/Changelog.md index 86ee627..c5289f5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,8 @@ Change Log: All notable changes to this project will be documented in this section. +### 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 ### 1.1.8 - Integrated Subtitles UI and added support to pass custom JWT Token when validating purchase diff --git a/PlayKitReadMe.md b/PlayKitReadMe.md index 2278119..5c5cf77 100644 --- a/PlayKitReadMe.md +++ b/PlayKitReadMe.md @@ -624,7 +624,7 @@ playKit.player?.setVolume(0.5F) To instruct PlayKit to use a certain track when streaming (if available), you can use the following function: ``` Kotlin -playKit.changeTrack(id: String?) +playKit.changeTrack(id: String) ``` PlayKit will atttempt to change the track to the chosen one for the rest of the stream. The id of the track should be the uniqueId of the available MediaTrack @@ -638,13 +638,21 @@ override fun tracksAvailable(tracks: List) { Once the tracks are available and ready, is possible to filter and select the chosen track in this way: ``` Kotlin -playKit.changeTrack(tracks.firstOrNull { it.language?.contains("english") == true && it.type == TrackType.TEXT }?.uniqueId) +tracks.firstOrNull { it.language?.contains("english") == true && it.type == TrackType.TEXT }?.let { track -> + playKit.changeTrack(track.uniqueId) +} ``` +Hovewer, PlayKit will take care to select the default caption track once the video will be loaded. + # Change Log All notable changes to this project will be documented in this section. +### 1.2.0 +- Default subtitle track auto-selected +- Get Label caption on subtitle selector + ### 1.1.8 - Subtitles UI selector diff --git a/README.md b/README.md index 636e5cc..642101e 100755 --- a/README.md +++ b/README.md @@ -68,3 +68,8 @@ alternatively, to install all SDK elements, use the following line: ``` Sync your Gradle files, and the AMG SDK should import and be available for use. + + +## Change Log + +All notable changes to this project will be documented [here](Changelod.md) diff --git a/build.gradle b/build.gradle index 014b3a4..465de97 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 = 20 -ext.SDK_VERSION_NAME = "1.1.9" +ext.SDK_VERSION_CODE = 21 +ext.SDK_VERSION_NAME = "1.2.0" 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 83fad45..9de3c83 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 @@ -246,9 +246,12 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface { tracks?.addAll(event.tracksInfo.textTracks.map { MediaTrack(it.uniqueId, TrackType.TEXT, it.language, it.label, it.mimeType) }) tracks?.addAll(event.tracksInfo.audioTracks.map { MediaTrack(it.uniqueId, TrackType.AUDIO, it.language, it.label, codecName = it.codecName, bitrate = it.bitrate, channelCount = it.channelCount) }) tracks?.addAll(event.tracksInfo.imageTracks.map { MediaTrack(it.uniqueId, TrackType.IMAGE, url = it.url, bitrate = it.bitrate, duration = it.duration, label = it.label, cols = it.cols, rows = it.rows, width = it.width.toInt(), height = it.height.toInt()) }) - tracks?.let { - listener?.tracksAvailable(it) - controlsView.createSubtitleSelector(it.filter { it.type == TrackType.TEXT }) + tracks?.let { tracks -> + tracks.filter { it.type == TrackType.TEXT }.let { textTracks -> + checkDefaultCaptionTrack(textTracks) + controlsView.createSubtitlesSelector(textTracks) + } + listener?.tracksAvailable(tracks) } } @@ -267,12 +270,49 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface { } - override fun setTrack(track: MediaTrack?) { - changeTrack(track?.uniqueId ?: "") + private fun checkDefaultCaptionTrack(textTracks: List) { + controlsView.selectedCaption = 0 + currentMediaItem?.captionAsset?.objects?.let { + for (caption in it) { // Find the Label first + if (caption.isDefault == true) { + textTracks.indexOfFirst { mediaTrack -> + mediaTrack.label == caption.label + }.let { defaultIndexCaptionTrack -> + if (defaultIndexCaptionTrack >= 0) { + player?.changeTrack(textTracks[defaultIndexCaptionTrack].uniqueId) + controlsView.setCaptionOnSelector(defaultIndexCaptionTrack) + return + } + } + } + } + for (caption in it) { // As fallback, find the Language if Label not set + if (caption.isDefault == true) { + textTracks.indexOfFirst { mediaTrack -> + mediaTrack.label == caption.language + }.let { defaultIndexCaptionTrack -> + if (defaultIndexCaptionTrack >= 0) { + player?.changeTrack(textTracks[defaultIndexCaptionTrack].uniqueId) + controlsView.setCaptionOnSelector(defaultIndexCaptionTrack) + return + } + } + } + } + } + } + + override fun setTrack(track: MediaTrack) { + changeTrack(track.uniqueId) } - fun changeTrack(id: String?) { + fun changeTrack(id: String) { player?.changeTrack(id) + tracks?.filter { it.type == TrackType.TEXT }?.indexOfFirst { mediaTrack -> + mediaTrack.uniqueId == id + }?.let { trackIndex -> + controlsView.setCaptionOnSelector(trackIndex) + } } fun getTracks() : List? { @@ -559,8 +599,6 @@ class AMGPlayKit : LinearLayout, AMGPlayerInterface { listBitrate = bitrates } - player?.changeTrack(mediaConfig.captionAsset?.objects?.lastOrNull()?.id) - controlsView.setMediaType(mediaType) if (mediaType == AMGMediaType.VOD){ isLive(mediaConfig.serverURL, mediaConfig.entryID, mediaConfig.ks){isLiveBool -> 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 c64af40..3b67a6f 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 @@ -66,7 +66,7 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface { var fadeTime: Long = 5000 var selectedBitrate = 0 - var selectedSubtitle = 0 + var selectedCaption: Int = 0 var shouldHideOnOrientation = -1 lateinit var mainView: ConstraintLayout @@ -501,7 +501,7 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface { append(spannable) } - fun createSubtitleSelector(subtitles: List) { + fun createSubtitlesSelector(subtitles: List) { subtitleSelectorView.removeAllViews() subtitles.forEachIndexed { index, mediaTrack -> subtitleSelectorView.addView(listDivider()) @@ -509,32 +509,32 @@ class AMGPlayKitStandardControl : LinearLayout, AMGControlInterface { } } - private fun subtitleButton(track: MediaTrack?, index: Int): Button { + private fun subtitleButton(track: MediaTrack, index: Int): Button { val btnSubtitle = standardButton() btnSubtitle.tag = index track?.label?.let { if (it == "none") { btnSubtitle.setText(R.string.subtitle_off) } else { - btnSubtitle.text = Locale(it).displayLanguage.replaceFirstChar { char -> char.uppercase() } + btnSubtitle.text = it } } - toggleSubtitleButton(index, btnSubtitle, selectedSubtitle == index) + toggleSubtitleButton(index, btnSubtitle, selectedCaption == index) btnSubtitle.setOnClickListener { Log.d("SUBTITLE","Selected subtitle: ${track?.label}") // Previous subtitle back to normal status - val btnPrevSubtitle = subtitleSelectorView.findViewWithTag