From a9a78ba67480ebb544b49fa8027116c34e0c29d1 Mon Sep 17 00:00:00 2001 From: Marcus Hanestad Date: Fri, 22 Aug 2025 10:05:32 +0200 Subject: [PATCH] casting: set metadata for video load requests --- .../experimental_casting/CastingDevice.kt | 6 ++- .../experimental_casting/StateCasting.kt | 44 ++++++++++++++----- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/futo/platformplayer/experimental_casting/CastingDevice.kt b/app/src/main/java/com/futo/platformplayer/experimental_casting/CastingDevice.kt index 6793b551..cc495e80 100644 --- a/app/src/main/java/com/futo/platformplayer/experimental_casting/CastingDevice.kt +++ b/app/src/main/java/com/futo/platformplayer/experimental_casting/CastingDevice.kt @@ -20,6 +20,7 @@ import org.fcast.sender_sdk.CastingDevice as RsCastingDevice; import org.fcast.sender_sdk.DeviceEventHandler as RsDeviceEventHandler; import org.fcast.sender_sdk.DeviceConnectionState import org.fcast.sender_sdk.LoadRequest +import org.fcast.sender_sdk.Metadata class CastingDeviceHandle { class EventHandler : RsDeviceEventHandler { @@ -110,10 +111,11 @@ class CastingDeviceHandle { contentId: String, resumePosition: Double, duration: Double, - speed: Double? + speed: Double?, + metadata: Metadata? = null ) { try { - device.load(LoadRequest.Video(contentType, contentId, resumePosition, speed, duration)) + device.load(LoadRequest.Video(contentType, contentId, resumePosition, speed, duration, metadata)) } catch (e: Throwable) { Logger.e(TAG, "Failed to load video: $e") } diff --git a/app/src/main/java/com/futo/platformplayer/experimental_casting/StateCasting.kt b/app/src/main/java/com/futo/platformplayer/experimental_casting/StateCasting.kt index 4589d537..60f8c413 100644 --- a/app/src/main/java/com/futo/platformplayer/experimental_casting/StateCasting.kt +++ b/app/src/main/java/com/futo/platformplayer/experimental_casting/StateCasting.kt @@ -62,6 +62,7 @@ import org.fcast.sender_sdk.CastingDevice as RsCastingDevice import org.fcast.sender_sdk.ProtocolType import org.fcast.sender_sdk.CastContext import org.fcast.sender_sdk.DeviceConnectionState +import org.fcast.sender_sdk.Metadata import org.fcast.sender_sdk.NsdDeviceDiscoverer import org.fcast.sender_sdk.urlFormatIpAddr import java.util.concurrent.atomic.AtomicInteger @@ -463,6 +464,13 @@ class ExpStateCasting { _castId.incrementAndGet() } + private fun metadataFromVideo(video: IPlatformVideoDetails): Metadata { + return Metadata( + title = video.name, + thumbnailUrl = video.thumbnails.getHQThumbnail() + ) + } + suspend fun castIfAvailable( contentResolver: ContentResolver, video: IPlatformVideoDetails, @@ -561,7 +569,8 @@ class ExpStateCasting { videoUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ) } else if (audioSource is IAudioUrlSource) { val audioPath = "/audio-${id}" @@ -572,7 +581,8 @@ class ExpStateCasting { audioUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); } else if (videoSource is IHLSManifestSource) { if (proxyStreams || ad.device.castingProtocol() == ProtocolType.CHROMECAST) { @@ -591,7 +601,8 @@ class ExpStateCasting { videoSource.url, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); } } else if (audioSource is IHLSManifestAudioSource) { @@ -611,7 +622,8 @@ class ExpStateCasting { audioSource.url, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); } } else if (videoSource is LocalVideoSource) { @@ -726,7 +738,8 @@ class ExpStateCasting { videoUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf(videoUrl); @@ -756,7 +769,8 @@ class ExpStateCasting { audioUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf(audioUrl); @@ -949,7 +963,8 @@ class ExpStateCasting { hlsUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ) return listOf(hlsUrl, videoUrl, audioUrl, subtitleUrl) @@ -1028,7 +1043,8 @@ class ExpStateCasting { dashUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf(dashUrl, videoUrl, audioUrl, subtitleUrl); @@ -1303,7 +1319,8 @@ class ExpStateCasting { hlsUrl, hackfixResumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf(hlsUrl); @@ -1575,7 +1592,8 @@ class ExpStateCasting { hlsUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf( @@ -1690,7 +1708,8 @@ class ExpStateCasting { dashUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf( @@ -1958,7 +1977,8 @@ class ExpStateCasting { dashUrl, resumePosition, video.duration.toDouble(), - speed + speed, + metadataFromVideo(video) ); return listOf()