Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Hollister 0a8e96cac8 Fixed local Dash webm video casting 2025-02-11 01:13:13 -06:00
Michael Hollister 1e941cf6c5 Fixed local HLS video casting 2025-02-11 01:06:08 -06:00
2 changed files with 6 additions and 4 deletions
@@ -46,7 +46,8 @@ class HttpFileHandler(method: String, path: String, private val contentType: Str
}
var totalBytesSent = 0
val contentLength = end - start + 1
val byteReadOffset = if (contentType == "video/webm" && end == 8192L) 0 else 1;
val contentLength = end - start + byteReadOffset
responseHeaders["Content-Length"] = contentLength.toString()
Logger.i(TAG, "Sending $contentLength bytes (start: $start, end: $end)")
@@ -59,7 +60,7 @@ class HttpFileHandler(method: String, path: String, private val contentType: Str
val outputStream = responseStream
while (true) {
val expectedBytesRead = (end - current + 1).coerceAtMost(buffer.size.toLong());
val expectedBytesRead = (end - current + byteReadOffset).coerceAtMost(buffer.size.toLong());
val bytesRead = inputStream.read(buffer);
if (bytesRead < 0) {
Logger.i(TAG, "End of file reached")
@@ -501,14 +501,15 @@ class StateCasting {
val id = UUID.randomUUID();
val videoPath = "/video-${id}"
val videoUrl = url + videoPath;
val videoContainer = if (videoSource.container == "application/vnd.apple.mpegurl") "video/mp4" else videoSource.container;
_castServer.addHandlerWithAllowAllOptions(
HttpFileHandler("GET", videoPath, videoSource.container, videoSource.filePath)
HttpFileHandler("GET", videoPath, videoContainer, videoSource.filePath)
.withHeader("Access-Control-Allow-Origin", "*"), true
).withTag("cast");
Logger.i(TAG, "Casting local video (videoUrl: $videoUrl).");
ad.loadVideo("BUFFERED", videoSource.container, videoUrl, resumePosition, video.duration.toDouble(), speed);
ad.loadVideo("BUFFERED", videoContainer, videoUrl, resumePosition, video.duration.toDouble(), speed);
return listOf(videoUrl);
}