mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-08 23:43:52 +08:00
fix: use snake_case field names matching Bilibili DASH API response
B站 API 实际返回 segment_base.initialization / index_range 而非 segmentBase.Initialization / indexRange,修正类型定义和 MPD 生成逻辑。 segment_base 设为可选,缺失时不生成 SegmentBase 元素(ExoPlayer fallback)。
This commit is contained in:
@@ -35,8 +35,8 @@ export interface Comment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DashSegmentBase {
|
export interface DashSegmentBase {
|
||||||
Initialization: string;
|
initialization: string;
|
||||||
indexRange: string;
|
index_range: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DashVideoItem {
|
export interface DashVideoItem {
|
||||||
@@ -48,7 +48,7 @@ export interface DashVideoItem {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
frameRate: string;
|
frameRate: string;
|
||||||
segmentBase: DashSegmentBase;
|
segment_base?: DashSegmentBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DashAudioItem {
|
export interface DashAudioItem {
|
||||||
@@ -57,7 +57,7 @@ export interface DashAudioItem {
|
|||||||
bandwidth: number;
|
bandwidth: number;
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
codecs: string;
|
codecs: string;
|
||||||
segmentBase: DashSegmentBase;
|
segment_base?: DashSegmentBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PlayUrlResponse {
|
export interface PlayUrlResponse {
|
||||||
|
|||||||
@@ -15,6 +15,16 @@ export function buildDashDataUri(playData: PlayUrlResponse, qn: number): string
|
|||||||
|
|
||||||
const dur = dash.duration;
|
const dur = dash.duration;
|
||||||
|
|
||||||
|
const vSeg = video.segment_base;
|
||||||
|
const aSeg = audio.segment_base;
|
||||||
|
|
||||||
|
const videoSegmentBase = vSeg
|
||||||
|
? `\n <SegmentBase indexRange="${vSeg.index_range}">\n <Initialization range="${vSeg.initialization}"/>\n </SegmentBase>`
|
||||||
|
: '';
|
||||||
|
const audioSegmentBase = aSeg
|
||||||
|
? `\n <SegmentBase indexRange="${aSeg.index_range}">\n <Initialization range="${aSeg.initialization}"/>\n </SegmentBase>`
|
||||||
|
: '';
|
||||||
|
|
||||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011"
|
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011"
|
||||||
profiles="urn:mpeg:dash:profile:isoff-on-demand:2011"
|
profiles="urn:mpeg:dash:profile:isoff-on-demand:2011"
|
||||||
@@ -23,18 +33,12 @@ export function buildDashDataUri(playData: PlayUrlResponse, qn: number): string
|
|||||||
<Period duration="PT${dur}S">
|
<Period duration="PT${dur}S">
|
||||||
<AdaptationSet id="1" mimeType="${video.mimeType}" codecs="${video.codecs}" startWithSAP="1" subsegmentAlignment="true">
|
<AdaptationSet id="1" mimeType="${video.mimeType}" codecs="${video.codecs}" startWithSAP="1" subsegmentAlignment="true">
|
||||||
<Representation id="v1" bandwidth="${video.bandwidth}" width="${video.width}" height="${video.height}" frameRate="${video.frameRate}">
|
<Representation id="v1" bandwidth="${video.bandwidth}" width="${video.width}" height="${video.height}" frameRate="${video.frameRate}">
|
||||||
<BaseURL>${escapeXml(video.baseUrl)}</BaseURL>
|
<BaseURL>${escapeXml(video.baseUrl)}</BaseURL>${videoSegmentBase}
|
||||||
<SegmentBase indexRange="${video.segmentBase.indexRange}">
|
|
||||||
<Initialization range="${video.segmentBase.Initialization}"/>
|
|
||||||
</SegmentBase>
|
|
||||||
</Representation>
|
</Representation>
|
||||||
</AdaptationSet>
|
</AdaptationSet>
|
||||||
<AdaptationSet id="2" mimeType="${audio.mimeType}" codecs="${audio.codecs}" startWithSAP="1" subsegmentAlignment="true">
|
<AdaptationSet id="2" mimeType="${audio.mimeType}" codecs="${audio.codecs}" startWithSAP="1" subsegmentAlignment="true">
|
||||||
<Representation id="a1" bandwidth="${audio.bandwidth}">
|
<Representation id="a1" bandwidth="${audio.bandwidth}">
|
||||||
<BaseURL>${escapeXml(audio.baseUrl)}</BaseURL>
|
<BaseURL>${escapeXml(audio.baseUrl)}</BaseURL>${audioSegmentBase}
|
||||||
<SegmentBase indexRange="${audio.segmentBase.indexRange}">
|
|
||||||
<Initialization range="${audio.segmentBase.Initialization}"/>
|
|
||||||
</SegmentBase>
|
|
||||||
</Representation>
|
</Representation>
|
||||||
</AdaptationSet>
|
</AdaptationSet>
|
||||||
</Period>
|
</Period>
|
||||||
|
|||||||
Reference in New Issue
Block a user