fix: quality switch not updating video playback

- Use qn-specific MPD filename (bili_dash_{qn}.mpd) so each quality
  produces a distinct URI that triggers react-native-video to reload
- Add key={resolvedUrl} on <Video> to force remount on source change
This commit is contained in:
Developer
2026-03-10 20:18:47 +08:00
parent 35371cebff
commit 03d7d3c5c3
2 changed files with 2 additions and 1 deletions

View File

@@ -57,6 +57,7 @@ export function NativeVideoPlayer({
<View style={[styles.container, style]}>
{resolvedUrl ? (
<Video
key={resolvedUrl}
ref={videoRef}
source={isDash
? { uri: resolvedUrl, type: 'mpd', headers: BILIBILI_HEADERS }

View File

@@ -7,7 +7,7 @@ import type { PlayUrlResponse } from '../services/types';
*/
export async function buildDashMpdUri(playData: PlayUrlResponse, qn: number): Promise<string> {
const xml = buildMpdXml(playData, qn);
const path = `${FileSystem.cacheDirectory}bili_dash.mpd`;
const path = `${FileSystem.cacheDirectory}bili_dash_${qn}.mpd`;
await FileSystem.writeAsStringAsync(path, xml, { encoding: FileSystem.EncodingType.UTF8 });
return path;
}