casting: set metadata for video load requests

This commit is contained in:
Marcus Hanestad 2025-08-22 10:05:32 +02:00
commit a9a78ba674
2 changed files with 36 additions and 14 deletions

View file

@ -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.DeviceEventHandler as RsDeviceEventHandler;
import org.fcast.sender_sdk.DeviceConnectionState import org.fcast.sender_sdk.DeviceConnectionState
import org.fcast.sender_sdk.LoadRequest import org.fcast.sender_sdk.LoadRequest
import org.fcast.sender_sdk.Metadata
class CastingDeviceHandle { class CastingDeviceHandle {
class EventHandler : RsDeviceEventHandler { class EventHandler : RsDeviceEventHandler {
@ -110,10 +111,11 @@ class CastingDeviceHandle {
contentId: String, contentId: String,
resumePosition: Double, resumePosition: Double,
duration: Double, duration: Double,
speed: Double? speed: Double?,
metadata: Metadata? = null
) { ) {
try { try {
device.load(LoadRequest.Video(contentType, contentId, resumePosition, speed, duration)) device.load(LoadRequest.Video(contentType, contentId, resumePosition, speed, duration, metadata))
} catch (e: Throwable) { } catch (e: Throwable) {
Logger.e(TAG, "Failed to load video: $e") Logger.e(TAG, "Failed to load video: $e")
} }

View file

@ -62,6 +62,7 @@ import org.fcast.sender_sdk.CastingDevice as RsCastingDevice
import org.fcast.sender_sdk.ProtocolType import org.fcast.sender_sdk.ProtocolType
import org.fcast.sender_sdk.CastContext import org.fcast.sender_sdk.CastContext
import org.fcast.sender_sdk.DeviceConnectionState import org.fcast.sender_sdk.DeviceConnectionState
import org.fcast.sender_sdk.Metadata
import org.fcast.sender_sdk.NsdDeviceDiscoverer import org.fcast.sender_sdk.NsdDeviceDiscoverer
import org.fcast.sender_sdk.urlFormatIpAddr import org.fcast.sender_sdk.urlFormatIpAddr
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
@ -463,6 +464,13 @@ class ExpStateCasting {
_castId.incrementAndGet() _castId.incrementAndGet()
} }
private fun metadataFromVideo(video: IPlatformVideoDetails): Metadata {
return Metadata(
title = video.name,
thumbnailUrl = video.thumbnails.getHQThumbnail()
)
}
suspend fun castIfAvailable( suspend fun castIfAvailable(
contentResolver: ContentResolver, contentResolver: ContentResolver,
video: IPlatformVideoDetails, video: IPlatformVideoDetails,
@ -561,7 +569,8 @@ class ExpStateCasting {
videoUrl, videoUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
) )
} else if (audioSource is IAudioUrlSource) { } else if (audioSource is IAudioUrlSource) {
val audioPath = "/audio-${id}" val audioPath = "/audio-${id}"
@ -572,7 +581,8 @@ class ExpStateCasting {
audioUrl, audioUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
} else if (videoSource is IHLSManifestSource) { } else if (videoSource is IHLSManifestSource) {
if (proxyStreams || ad.device.castingProtocol() == ProtocolType.CHROMECAST) { if (proxyStreams || ad.device.castingProtocol() == ProtocolType.CHROMECAST) {
@ -591,7 +601,8 @@ class ExpStateCasting {
videoSource.url, videoSource.url,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
} }
} else if (audioSource is IHLSManifestAudioSource) { } else if (audioSource is IHLSManifestAudioSource) {
@ -611,7 +622,8 @@ class ExpStateCasting {
audioSource.url, audioSource.url,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
} }
} else if (videoSource is LocalVideoSource) { } else if (videoSource is LocalVideoSource) {
@ -726,7 +738,8 @@ class ExpStateCasting {
videoUrl, videoUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf(videoUrl); return listOf(videoUrl);
@ -756,7 +769,8 @@ class ExpStateCasting {
audioUrl, audioUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf(audioUrl); return listOf(audioUrl);
@ -949,7 +963,8 @@ class ExpStateCasting {
hlsUrl, hlsUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
) )
return listOf(hlsUrl, videoUrl, audioUrl, subtitleUrl) return listOf(hlsUrl, videoUrl, audioUrl, subtitleUrl)
@ -1028,7 +1043,8 @@ class ExpStateCasting {
dashUrl, dashUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf(dashUrl, videoUrl, audioUrl, subtitleUrl); return listOf(dashUrl, videoUrl, audioUrl, subtitleUrl);
@ -1303,7 +1319,8 @@ class ExpStateCasting {
hlsUrl, hlsUrl,
hackfixResumePosition, hackfixResumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf(hlsUrl); return listOf(hlsUrl);
@ -1575,7 +1592,8 @@ class ExpStateCasting {
hlsUrl, hlsUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf( return listOf(
@ -1690,7 +1708,8 @@ class ExpStateCasting {
dashUrl, dashUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf( return listOf(
@ -1958,7 +1977,8 @@ class ExpStateCasting {
dashUrl, dashUrl,
resumePosition, resumePosition,
video.duration.toDouble(), video.duration.toDouble(),
speed speed,
metadataFromVideo(video)
); );
return listOf() return listOf()