-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Loading a video/audio as an assets does not work. #3725
Comments
This config works for me.
Edit: Don't do this. It's dangerous: #3735 (comment) |
As i said in the other issue, you shouldn't configure the scope like this (Especially since we are working on a fix).
About scope errors: It should be logged to the terminal (in |
This is not a scope issue. My scope already looks like this: "protocol": {
"all": false,
"asset": true,
"assetScope": ["*"]
}, For my project this is necessary as the file explorer that i'm building requires the capability to, you know, display files :p. |
Ah whoops, didn't see that you were 2 different people, sorry. |
Did you try adding media-src in csp? Add |
@red010182 |
@firstdorsal do you have a reproduction? I have a video conversion app I'm making and I'm able to display user-uploaded videos (from tauri dialog) in a {
// ...
"protocol": {
"asset": true
},
// ...
"security": {
"csp": "default-src: 'self'; media-src 'self' asset:"
}
} |
I can reproduce this issue, seems to be a webkit2gtk problem. |
Is there a workaround that we can use? Or we just wait for a proper fix? |
If you mean using the "Native" browser dialog to select a video then this is not related I think. @lucasfernog great, good to know! Is this working on Win/Mac? |
I never had issues on Windows and macOS. And I don't know about a workaround :/ |
@wusyong was investigating this issue, I think it's a problem with latest webkit2gtk. |
Is |
Also, is there an upstream bug report? I can't find one. |
|
I tried to open this page on wry like the following. let webview = WebViewBuilder::new(window)?.with_url("https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/HTML/Element/video/_sample_.single_source.html")?; But this shows the empty video screen . Screen.Recording.2022-07-30.at.19.41.28.movedit: oops, this is my mistakes. webkitgtk seems to need to install gstreamer... |
Maybe issue is here for webkitgtk |
It's weird 'cause I was sure it worked on previous webkit2gtk releases :( |
Loading audio with the asset protocol is also broken |
It seems fixed in 2.36.4. |
Hi all, |
Commenting the function name so others can find this issue when they search for |
For the people who are on Linux, images can be loaded through asset protocol (#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 : import { readBinaryFile } from "@tauri-apps/api/fs"
const [urlAudio, setUrlAudio] = useState<string>("")
return (
<>
<Button
variant="ghost"
onClick={() => {
const filePath = .....
void readBinaryFile(filePath)
.catch((err) => {
console.error(err)
})
.then((res) => {
const fileBlob = new Blob([res as ArrayBuffer], { type: "audio/mpeg" })
const reader = new FileReader()
reader.readAsDataURL(fileBlob)
const url = URL.createObjectURL(fileBlob)
setUrlAudio(url)
})
}}
className="w-full justify-start font-normal"
>
ok
</Button>
<audio controls>
<source src={urlAudio} type="audio/mpeg" />
</audio>
</>
) You just need to setup tauri.conf.json permission for letting fs reading files with 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 const filePath = "/home/yanovskyy/Musique/Shinigami.m4a"
fetch(convertFileSrc(filePath))
.then((res) => {
// create blob url from response
res
.blob()
.then((blob) => {
const url = URL.createObjectURL(blob)
setUrlAudio(url)
})
.catch((err) => {
console.error(err)
})
})
.catch((err) => {
console.error(err)
}) 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 ... |
This is quite annoying |
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 <audio controls>
<source src="/switch.ogg" type="audio/ogg" />
</audio> and placed the corresponding sound file in 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 <script lang="ts">
import clickSound from "$lib/sounds/switch.ogg";
...
function playClick() {
const audio = new Audio(clickSound);
audio.play();
}
</script>
<button
...
on:click={playClick}
>
...
</button> I get the error
where
|
[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. - Because of a linux specific issue, documented below, a file server workaround will be used. Main Issue:tauri-apps/tauri#3725 Fix Guide: tranxuanthang/lrcget@0a2fe99 See mention: tauri-apps/tauri#3725 (comment) [Dependencies] Added axum = "0.6.19" Added tokio = { version = "1.29.1", features = ["full"] } Added tower-http = { version = "0.4.3", features = ["fs", "cors"] }
Does it happens in Apple webkit as well? Looks very related to the bug in Linux Looks like both Update: |
gstreamer is only used on Linux. The issue in your case should be that you're providing a plain file path while it needs the asset: protocol (via convertFileSrc). |
@FabianLars |
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. |
Fix for a bug with webkitgtk used by Tauri tauri-apps/tauri#3725
I'm running into this issue on Linux (MP3 audio playback works with dev but not release build), except its happening not just for assets but also remote MP3 URL playback. Does anyone know of a workaround on Linux? |
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? |
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. |
@Siirko @superkelvint please take a look at references to this issue, they are available in the discussion above. Please do not bump same issue with same questions. luxuereal/Alexandria_EBook_Tauri@1050664 this might be helpful.
https://bugs.webkit.org/show_bug.cgi?id=146351 Here is the original bug report and discussion in webkit bug tracker. Tauri didn't do anything on it's side yet, and I don't think it can do for now. As it will break one of the core feature: working without running local server. |
Thanks for the information. I didn't realize it was the issue on webgtk gstreamer itself. I understand that Tauri cannot do anything about it. Looks like it's already been 9 years since the issue was raised and I don't think it is going to be fixed anytime soon. So I'll just spin up a http server as a workaround. |
A quick workaround that I resorted to for audio files:
Less than ideal, but does the job for small/short audio files. |
cursed way to fix this issue: const blobUrl = URL.createObjectURL(await fetch(asset).then(res => res.blob()))
const sound = new Audio(blobUrl) |
Perhaps it could be worked around by Tauri by allowing to register custom response generator under a path of default scheme? Something like Could WebviewBuilder::on_web_resource_request be the solution? |
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. |
I understand. I assumed this is possible: tauri-apps/wry#1087 |
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. |
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 workLoading 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
Stack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: