feat: implement HLS streaming support in VideoPlayer and enhance stream URL handling
This commit is contained in:
@@ -42,7 +42,10 @@ impl JellyfinMediaProvider {
|
||||
pub fn new(config: JellyfinConfig) -> Self {
|
||||
Self {
|
||||
client: reqwest::Client::new(),
|
||||
config,
|
||||
config: JellyfinConfig {
|
||||
base_url: config.base_url.trim_end_matches('/').to_string(),
|
||||
..config
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,21 +156,23 @@ impl IMediaProvider for JellyfinMediaProvider {
|
||||
Ok(body.items.into_iter().next().and_then(map_jellyfin_item))
|
||||
}
|
||||
|
||||
/// Build a stream URL for a Jellyfin item.
|
||||
/// Build an HLS stream URL for a Jellyfin item.
|
||||
///
|
||||
/// Requests H.264 video + AAC audio in an MP4 container so that all
|
||||
/// major browsers can play it natively. Jellyfin will direct-play if the
|
||||
/// source already matches; otherwise it transcodes on the fly.
|
||||
/// A high `VideoBitRate` (40 Mbps) preserves quality on local networks.
|
||||
/// The API key is embedded in the URL so the player needs no separate auth.
|
||||
/// Returns a `master.m3u8` playlist URL. Jellyfin transcodes to H.264/AAC
|
||||
/// segments on the fly. HLS is preferred over a single MP4 stream because
|
||||
/// `StartTimeTicks` works reliably with HLS — each segment is independent,
|
||||
/// so Jellyfin can begin the playlist at the correct broadcast offset
|
||||
/// without needing to byte-range seek into an in-progress transcode.
|
||||
///
|
||||
/// Note: the caller (stream proxy route) may append `StartTimeTicks` to
|
||||
/// seek to the correct broadcast offset before returning the URL to the client.
|
||||
/// The API key is embedded so the player needs no separate auth header.
|
||||
/// The caller (stream proxy route) appends `StartTimeTicks` when there is
|
||||
/// a non-zero broadcast offset.
|
||||
async fn get_stream_url(&self, item_id: &MediaItemId) -> DomainResult<String> {
|
||||
Ok(format!(
|
||||
"{}/Videos/{}/stream?videoCodec=h264&audioCodec=aac&container=mp4&VideoBitRate=40000000&api_key={}",
|
||||
"{}/Videos/{}/master.m3u8?videoCodec=h264&audioCodec=aac&VideoBitRate=40000000&mediaSourceId={}&api_key={}",
|
||||
self.config.base_url,
|
||||
item_id.as_ref(),
|
||||
item_id.as_ref(),
|
||||
self.config.api_key,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user