In Stack Overflow or other example, I found that from asset folder and from network I can play audio file easily.
But, There is no clear approach That I can play audio file from Application Storage or mobile device.
My Audio path is : String playebleFilePath = '/Users/noorhossain/Library/Developer/CoreSimulator/Devices/5C9813C4-7773-4013-B086-279DB8FCA64F/data/Containers/Data/Application/F905830C-C698-4FEB-80F1-FB386BE18882/Library/Application Support/VocalDatabaseAudio/word_audio_one/2.mp3'
final assetsAudioPlayer = AssetsAudioPlayer();
assetsAudioPlayer.open(
Audio.file(playebleFilePath),
);
How can I play Audio from this storage path ?
My error log says : plugin Exception, cannot find the file in this server.
Any solution ?
I think the exception is due to the fact that the file you are trying to play is not in the assets folder which will cause the plugin to throw an exception.
i have been using audioplayers plugin and for assets it actually has a prefix to the path that actually points to an "assets" folder, the assets folder should also be correctly referenced in the pubspec.yaml file...
then more importantly since it seems you want to use app directory, consider using something like:await audioPlayer .play(DeviceFileSource("directory/path to your song"));
just check out the getting started of the audioplayers library: [ [1]: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md][1]
Related
I am loading some assets from assetBundles that I store online. I want to cash some of them but I need a bundle manifest for That.I am using this to build the bundle.
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.Android);
This gives me enter image description here, first file is assetBundle, the secound is manifest for that assetbundle. Based on what I found online I think it should also create a manifest named atlases (for the folder), but it doesnt.
If i try to load one of the assetBundle manifests using this
AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "atlases/atlascity1") //fails with error: "Unable to open archive file: C:/ProjectPath/StreamingAssets/atlases/atlascity1"
//ver. B:
AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "atlases/atlascity1.manifest") //fails with error: "Unable to read header from archive file: C:/ProjectPath/StreamingAssets/atlases/atlascity1.manifest"
What am I missing?
when I use library, image_picker, I have errors Task "'assembleAarRelease' not found in root project 'alert'."
but I remove image_picker in pubspec, the application work well
I need both alert and image_picker
enter image description here
At the moment i build a chat similar in wahtsapp.
I would like upload some local files (pdf, txt, image...).
Like this:
I try to get the local files via path_provider.
But i dont get access to download folder.
My problem:
I don't know how i can access the dowload folder with path_provider.
See my code:
//load local files from download folder
_loadLocalFile() async {
//absoulute path to download file
var file = io.Directory('/storage/emulated/0/Download/')
.listSync(); //use your folder name insted of resume.
//console output -> []
//other try to get download folder
List<io.Directory>? documents = await getExternalStorageDirectories();
//console output -> [Directory: '/storage/emulated/0/Android/data/de.securebuy.securebuy/files', Directory: '/storage/1BEC-0908/Android/data/de.securebuy.securebuy/files']
print(documents.toString());
}
I also add to AndroidManifest following rules:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE”/>
Anyone have a idea how i can build a function similar in image?
Is that possible?
Many thx
till now , pathprovider isn't going to let you in downloads file , so if you are on android you can just write the downloads directory , else using android_path_provider it is a null-safety package and you can accsess it via :var downloadsPath = await AndroidPathProvider.downloadsPath; , on ios you can get only the app directory cuase ios makes it's own file for every app thus we use 'pathprovider' with Directory appDocDir = await getApplicationDocumentsDirectory();
Update :
i see what you are trying to achieve and this is not what pathprovider pcakage is used for , you have to use file_picker , read thier docs , i thinks that this is what you need
I have an module with an 'assets' folder located in the same directory as my pubspec.yaml file. In my assets folder I have test.txt, and simpleObject.json.
flutter:
assets:
- assets/test.txt
- assets/simpleObject.json
I believe the following code should then allow me to read it into my app.
var test = await DefaultAssetBundle.of(context).loadString("assets/test.txt");
Sadly I get the following error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Unable to load asset: assets/test.txt
The error comes from the asset_bundle.dart. I have to assume this is my fault, but according to everything I've read I'm doing it correctly. Any thoughts?
Here is my file structure if it helps.
MyModule
|_assets/test.txt
|_lib/
|_pubspec.yaml
I got a solution. Even though my package was trying to load its own asset, it still had to specify itself as the location.
Here is how my_package loads an image asset (specifying the package), uses it in a widget, and that widget is easily used by outside apps.
Image.asset(AssetImage("assets/splash.png").assetName, package: 'my_package',);
This is a bit late, but another solution can be:
Image.asset('packages/<package_name>/assets/splash.png');
I encountered this problem and took a lot of time before it was resolved.
The solution was to downgrade to a previous version (git checkout v1.5.4-hotfix.2)
We are building a Hololens app which is going to use asset bundles from the device folders, but we are getting a 'Unable to open archive file' error when trying to load the bundle files.
As we don't have much experience with asset bundles we started this by creating a very simple bundle file (just a few Unity primitives and materials) and we made a first try loading them into the app from the Unity editor. That is working as expected but it fails when we deploy the app into our Hololens.
This is our loading method:
#if WINDOWS_UWP
public async void CallForBundles()
#else
public void CallForBundles()
#endif
{
string bundleFile = "--- NO BUNDLE ---";
#if UNITY_EDITOR
bundleFile = #"D:\temp\UnityBuilds\AssetBundles\exportablebundle";
#endif
#if WINDOWS_UWP
Windows.Storage.StorageFolder objectsFolder = Windows.Storage.KnownFolders.Objects3D;
Windows.Storage.StorageFile bundleFilePointer = await objectsFolder.GetFileAsync("exportablebundle");
bundleFile = bundleFilePointer.Path;
#endif
var myLoadedAB = AssetBundle.LoadFromFile(bundleFile);
//instante bundle components from myLoadedAB//
}
As you see is something very simple. We find the bundle path by different methods depending on the platform (we already used this system for text files, pngs and others) and the UNITY_EDITOR side is working. The WINDOWS_UWP is throwing this error just on the call to AssetBundle.LoadFromFile(bundleFile);:
Unable to open archive file: C:/Data/Users/edata/3D Objects/exportablebundle
(Filename: C:\buildslave\unity\build\Runtime/VirtualFileSystem/ArchiveFileSystem/ArchiveStorageReader.cpp Line: 542)
'Holoplan.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\HoloplanVS.Release_x86.jalfonso\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
NullReferenceException: Object reference not set to an instance of an object.
at GameManager.<CallForBundles>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at UnityEngine.UnitySynchronizationContext.WorkRequest.Invoke()
at UnityEngine.UnitySynchronizationContext.Exec()
at UnityEngine.UnitySynchronizationContext.ExecuteTasks()
at UnityEngine.UnitySynchronizationContext.$Invoke1(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: <Unknown> Line: 0)
"Unable to open archive file: C:/Data/Users/edata/3D Objects/exportablebundle"
seems to be the same error that happens when the app try to load a bunde with wrong file name or path even when running on the editor so it looks like that for some reason 'AssetBundle.LoadFromFile' can't locate de file. We checked the bundleFile at that line and it contains the right filepath ('C:\Data\Users\edata\3D Objects\exportablebundle' where 'exportablebundle' is the bundle file name), so we guess that 'AssetBundle.LoadFromFile' has issues when reading from the Hololens local folder but we don't have much idea about how to address this.
¿Anyone can lend us a hand, please?
EDIT-
We are building our asset bundle with the sample code from the Unity manual in 'Asset bundle workflow'. Is like this:
static void BuildAllAssetBundles(){
string assetBundleDirectory = "Assets/AssetBundles";
if (!Directory.Exists(assetBundleDirectory)){
Directory.CreateDirectory(assetBundleDirectory);
}
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
'StandaloneWindows' as build target seems the closest to hololens from the available list so we went for it.
Sorry, asset bundling isn't working in HL devices right now. It's known issue that has to be fixed.