tauri: [bug] Loading a video/audio as an assets does not work.
Describe the bug
Loading a video as an asset does not work.
I followed the guide here: https://tauri.studio/docs/api/js/modules/tauri
It works fine with image files (png/jpg etc.) but not with videos.
I tried loading the video https://www.w3schools.com/html/mov_bbb.mp4 directly from the URL, and this worked without problems.
But using the asset:///home/paul/Downloads/mov_bbb.mp4 URL this does not work
Loading images from the same folder does work.
In the network panel you can see that the request failed but no further reason is specified


The loading of assets this way is IMO not very good explained and when it fails, for some reason, it is very difficult to find out why.
Thank you for creating Tauri, it is awesome!
Reproduction
No response
Expected behavior
No response
Platform and versions
Operating System - Arch Linux, version Rolling Release X64
Node.js environment
Node.js - 17.7.1
@tauri-apps/cli - 1.0.0-rc.6
@tauri-apps/api - 1.0.0-rc.2
Global packages
npm - 8.5.4
pnpm - Not installed
yarn - 1.22.17
Rust environment
rustup - 1.24.3
rustc - 1.59.0
cargo - 1.59.0
toolchain - stable-x86_64-unknown-linux-gnu
App directory structure
/dist
/node_modules
/src-tauri
/src
/.git
/public
App
tauri - 1.0.0-rc.4
tauri-build - 1.0.0-rc.4
tao - 0.6.4
wry - 0.13.3
build-type - build
CSP - default-src tauri: asset: https://asset.localhost
distDir - ../dist
devPath - http://localhost:3000/
framework - React
Stack trace
No response
Additional context
No response
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 17
- Comments: 69 (23 by maintainers)
Commits related to this issue
- Optimized Book Loading, Linux Workaround... [Changelog] - Epubs are now loaded by URL instead of through invoke. - This removes the need to serialize the bytes, and massively speeds up loading times.... — committed to btpf/Alexandria by btpf 3 years ago
- Optimized Book Loading, Linux Workaround... [Changelog] - Epubs are now loaded by URL instead of through invoke. - This removes the need to serialize the bytes, and massively speeds up loading times.... — committed to luxuereal/Alexandria_EBook_Tauri by luxuereal 3 years ago
- Optimized Book Loading, Linux Workaround... [Changelog] - Epubs are now loaded by URL instead of through invoke. - This removes the need to serialize the bytes, and massively speeds up loading times.... — committed to luxuereal/Alexandria_EBook_Tauri by luxuereal 3 years ago
- fix: workaround play bgm in release build See https://github.com/tauri-apps/tauri/issues/3725 — committed to AOSC-Dev/deploykit-gui by eatradish 3 years ago
- Read audio files using local HTTP server Fix for a bug with webkitgtk used by Tauri https://github.com/tauri-apps/tauri/issues/3725 — committed to vjousse/pomodorolm by vjousse 3 years ago
For the people who are on Linux, images can be loaded through asset protocol (https://github.com/tauri-apps/tauri/discussions/1438) but not for videos and audio due to webkit lib issue (see https://bugs.webkit.org/show_bug.cgi?id=146351, last email). Someone on tauri discord found a workaround for audio file (this maybe applicable to other type of file), you just have to load the file with fs and create a Blob which you create an DataURL with it
Example :
You just need to setup tauri.conf.json permission for letting fs reading files with
"scope": ["**"]EDIT : you could do even better with a simple fetch, you will have to add linux-protocol-headers to the features of tauri your cargo.toml file
And the code simplifies to
This, I think, is the best workaround for small video/audio file this moment because readBinaryFile slow down the process and there is memory problem. If you have big files (up to GB), well rip …
There are 2 issues mixed up here:
I can reproduce this issue, seems to be a webkit2gtk problem.
@Siirko yes. you can try to read the thread and find references from commits from other repos to this issue
cursed way to fix this issue:
This is quite annoying I hope webkit lib solves it soon, although would still be problematic for users who haven’t updated the lib
I got an issue where i need to load image and video inside tauri as an asset where the file is located in randomly path, but i solve that issue by copying the file inside tauri PATH, in my case i use appDataDir and it work just fine
My example app:
I use
react-playerin this example and work fineMy code
Commenting the function name so others can find this issue when they search for
convertFileSrc.asset://is Linux and macOS andhttps://asset.localhost/is Windows.This config works for me.
Edit:
Don’t do this. It’s dangerous: https://github.com/tauri-apps/tauri/issues/3735#issuecomment-1072978250
I’ve encountered this exact issue while building audio applications in Tauri. The
asset://protocol limitations on Linux (webkit2gtk) are particularly frustrating so I ended up creating a library specifically to solve this.NPM: desktop-audio-proxy github: DAP
As mentioned in this issue, Tauri’s
asset://protocol has webkit2gtk limitations that prevent reliable audio/video streaming, especially on Linux. The CSP and protocol restrictions make it unnecessarily complex to handle media files.How it’s used:
How to Use DAP with Videos:
Instead of fighting with protocol limitations, the library serves media files through a local HTTP proxy that webkit2gtk handles perfectly. It’s the same approach that works reliably in browsers, adapted for desktop applications. This has solved the asset loading issue for multiple of my Tauri projects dealing with audio/video streaming across different platforms
Still the same alternatives/workarounds as mentioned earlier in this issue:
Because we do not want to add a http server into tauri itself (assuming nobody changed their minds), we’re stuck with this until we have an alternative for webkitgtk.
webkitgtk still has issues to load video from custom URL scheme. I also have a reproducible example in pure C. https://github.com/wusyong/gtkbrowser/tree/video But I couldn’t track the upstream issue. I’ll find some time to open one again (or find the one I commented before.)
I have same problem but with images on MacOS This code fix this issue
"protocol": { "asset": true }, "security": { "csp": "default-src: 'self'; media-src 'self' asset:" },Loading audio with the asset protocol is also broken
Yeah it doesn’t because that’s exactly what this issue is about. And no, there were no updates and there very likely won’t be any until we drop webkitgtk.
I would have liked to see something similar to our existing localhost plugin that serves videos over http but that never happened and at this point probably never will.
Yeah that would be cool but only windows supports modifying arbitrary http requests/responses like that (and it’s also how the current custom protocol implementation works on windows). The current macOS and Linux webviews only support monitoring requests.
This is exactly how the default tauri and asset protocols work and the root cause of the issue here so yet another protocol with the same implementation would not help anyone.
Perhaps it could be worked around by Tauri by allowing to register custom response generator under a path of default scheme? Something like
tauri::Builder::default().register_uri_path("/videos", |_app, request| { ..., where all requests going to/videoswould be handled by custom code?Could WebviewBuilder::on_web_resource_request be the solution?
Any updates on this? I’ve been holding off a feature in Linux that allows video play from local asset. Can anyone from the team please respond if there are any alternatives?
That codebase is shared between apple, webkitgtk, and wpe (and more?). So having a gstreamer folder doesn’t mean much for the macos port, especially if we take a look at what other folders are in that mediastream folder.
I’m not sure if this is the same bug, but I’m unable to play bundled audio files. I’m using SvelteKit and doing
and placed the corresponding sound file in
src-svelte/static/switch.ogg. I can play this sound onyarn tauri devbut not the release build. Other assets such as font files or images in the static directory load just fine.If instead I set the audio source to be some random file from https://en.wikipedia.org/wiki/Category:Wikipedia_Ogg_files, then that external sound file plays successfully even on the release build.
If instead I place the file in
src-svelte/src/lib/sounds/switch.oggand try to programmatically play the sound:I get the error
where
console.log(clickSound)gives meconvertFileSrcdoesn’t appear to help either.I can load an image asset but not for audio/video asset even with correct configuration.
Don’t mind our project boards yet, we’re just playing around with them, trying to find something that works for us. In the latest iteration they only contain PRs which is why this issue was removed.
Looks like the issue still remains and I tried my best to write a C example to report back: https://bugs.webkit.org/show_bug.cgi?id=146351#c5
Hi all, I don’t know if it helps, I have just tested a basic video sample using the asset protocol. With a regular up-to-date ubuntu release, using webkitgtk2.36.6. Videos are still not playing on my station. Hopefully the next webkitgtk releases will have it fixed 😃
It’s weird 'cause I was sure it worked on previous webkit2gtk releases 😦
Is there a workaround that we can use? Or we just wait for a proper fix?
Ah whoops, didn’t see that you were 2 different people, sorry.