flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
Unity's video player doesn't work on Flutter
Hello, i am not able to use Unity's video player. It stays on black screen. Is there any way that i can fix this bug ? Thank you very much. :)
I have the same problem.
This is the error message I get in flutter android studio:
V/NuMediaExtractor(17144): NuMediaExtractor destructor V/NuMediaExtractor(17144): NuMediaExtractor constructor W/Unity (17144): AndroidVideoMedia::OpenExtractor could not translate sharedassets0.resource to local file. Make sure file exists, is on disk (not in memory) and not compressed. W/Unity (17144): (Filename: Line: 333) W/Unity (17144): W/Unity (17144): AndroidVideoMedia: Error opening extractor: -10004 W/Unity (17144): (Filename: Line: 469) W/Unity (17144):
Is there any way to fix this?
This is caused by how the video file is included in the build.
The videoplayer can play videos from a remote url or the local StreamingAssets folder. It is just the videos that are directly assigned in the editor that don't work.
Thank you, I used the Streaming Asset and it worked.
I've added a transparent .webm video to unity, and the transparency works well there, however when I build unity to flutter, the transparency turns white and is no longer transparent.
What can I do to get the video to be transparent?
Decided to look into this again. Video's included in a Unity scene or prefab get included into an asset file, which gets compressed when the app is built. Unity can't handle that compression and you will get an error like this
V/NuMediaExtractor(25662): NuMediaExtractor constructor
W/Unity (25662): AndroidVideoMedia::OpenExtractor could not translate sharedassets0.resource to local file. Make sure file exists, is on disk (not in memory) and not compressed.
W/Unity (25662): (Filename: Line: 333)
W/Unity (25662):
W/Unity (25662): AndroidVideoMedia: Error opening extractor: -10004
W/Unity (25662): (Filename: Line: 469)
W/Unity (25662):
I already mentioned 2 solutions that avoid the compression:
- Stream the video from a remote url.
- Play the video from the StreamingAssets folder.
A transparent webm video on android can only keep the transparency if it is transcoded by unity. Both these solutions skip the transcoding step from Unity and won't work, therefore we need to avoid the compression.
- Disable compression in
flutter project/android/app/build.gradle. Add apptOptions with noCompress, listing the required filetypes.
In my case the error told me it was insharedassets0.resource, so let's add '.resource'.
android {
lintOptions {...}
defaultConfig {...}
aaptOptions {
noCompress = ['.resource']
}
}
Here is a transparent .webm from a Google AR example project. (Tested with fuw 2022.1.0+7, Unity 2019.4.40 and 2021.3.5)
https://user-images.githubusercontent.com/11444698/176543711-d1dee1f1-0d2a-43b4-bb17-89672e436d09.mp4
This might result in larger app sizes if you have other assets that get packed in .resource files. But you can probably play around with using noCompress on specific filenames or making separate assetbundles in unity.
android {
lintOptions {...} defaultConfig {...} aaptOptions { noCompress = ['.resource'] }}
This saved me thanks timbotimbo!