Skip to content

fix: load video tags via relative src instead of file:// URI#20732

Open
Ayush-Patel-56 wants to merge 1 commit intoankidroid:mainfrom
Ayush-Patel-56:fix-20668-video-cors
Open

fix: load video tags via relative src instead of file:// URI#20732
Ayush-Patel-56 wants to merge 1 commit intoankidroid:mainfrom
Ayush-Patel-56:fix-20668-video-cors

Conversation

@Ayush-Patel-56
Copy link
Copy Markdown
Contributor

Purpose / Description

Fixes an issue where video files in [sound:] tags fail to load due to CORS policies blocking file:/// paths when the WebView base URL is http://127.0.0.1.

Fixes

Fixes #20668

Approach

Replaced the file:/// URI generation for <video src="..."> with just the raw relative filename.

The ViewerResourceHandler will natively intercept these requests and respond with Range headers over HTTP. This cleanly solves the cross-origin bug without sacrificing video seeking capabilities or needing an external activity.

How Has This Been Tested?

Built locally. Tested on a flashcard with an embedded video file to verify that the inline <video> tag loads the player and successfully plays back with functioning playback/scrubbing controls.

Video:

untitled.mp4

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@BrayanDSO
Copy link
Copy Markdown
Member

Please test it with some special chars that probably should be encoded: %, , numbers, kanji, emoji, etc

@BrayanDSO BrayanDSO added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Apr 16, 2026
@Ayush-Patel-56
Copy link
Copy Markdown
Contributor Author

Thanks for pointing it out, I've updated the PR with URI encoding for the src attribute and fixed the path resolution in ViewerResourceHandler. Using the filename test % 123 汉字 😄.mp4, the video loads and plays perfectly!

@david-allison david-allison added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Apr 19, 2026
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/multimedia/SoundUtils.kt Outdated
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/ViewerResourceHandler.kt
@BrayanDSO BrayanDSO added the Needs Author Reply Waiting for a reply from the original author label Apr 22, 2026
@BrayanDSO BrayanDSO removed the Needs Author Reply Waiting for a reply from the original author label Apr 23, 2026
@BrayanDSO
Copy link
Copy Markdown
Member

Asked for a apkg for reproduction in the original issue #20668 (comment)

@BrayanDSO BrayanDSO added Needs Author Reply Waiting for a reply from the original author labels Apr 23, 2026
@Ayush-Patel-56
Copy link
Copy Markdown
Contributor Author

sent apkg file in the comment #20668 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Video files in [sound:] tags don't load — file:// src blocked by cross-origin policy from http://127.0.0.1 base URL

3 participants