using flutter I try top open my audio from gallery in app as a ListView
I try to get audios from Gallery using photo_mager:-
List<AssetEntity>? media;
fetchAudio() async {
List<AssetPathEntity> albumsAudio =
await PhotoManager.getAssetPathList(type: RequestType.audio);
if (albumsAudio.isEmpty) return;
media = await albumsAudio[0].getAssetListPaged(page: 0, size: 60);
int dur = media![0].duration;
print('imageeeeee $dur');
media!.length;
}
and paly the url of audio using audio_palyer:-
File newFile = await media![index].file;
_audioPlayer.play( newFile!.path);
BUT it give me this error
E/flutter (22117): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(Unexpected error!, /storage/emulated/0/Download/09.Wehyati Khaliki.Starz.mp3: open failed: ENOENT (No such file or directory), java.io.FileNotFoundException: /storage/emulated/0/Download/09.Wehyati Khaliki.Starz.mp3: open failed: ENOENT (No such file or directory)
E/flutter (22117): at libcore.io.IoBridge.open(IoBridge.java:496)
E/flutter (22117): at java.io.FileInputStream.<init>(FileInputStream.java:159)
E/flutter (22117): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1238)
E/flutter (22117): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1216)
E/flutter (22117): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1181)
E/flutter (22117): at xyz.luan.audioplayers.WrappedMediaPlayer.setUrl(WrappedMediaPlayer.kt:37)
E/flutter (22117): at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.kt:59)
E/flutter (22117): at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.kt:33)
E/flutter (22117): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (22117): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter (22117): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/flutter (22117): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$AIEPqY6mWzaNK15HekX9bftoAXs.run(Unknown Source:12)
E/flutter (22117): at android.os.Handler.handleCallback(Handler.java:883)
E/flutter (22117): at android.os.Handler.dispatchMessage(Handler.java:100)
E/flutter (22117): at android.os.Looper.loop(Looper.java:224)
E/flutter (22117): at android.app.ActivityThread.main(ActivityThread.java:7561)
E/flutter (22117): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (22117): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
E/flutter (22117): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
E/flutter (22117): Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
E/flutter (22117): at libcore.io.Linux.open(Native Method)
E/flutter (22117): at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
E/flutter (22117): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
E/flutter (22117): at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
E/flutter (22117): at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7458)
E/flutter (22117): at libcore.io.IoBridge.open(IoBridge.java:482)
E/flutter (22117): ... 18 more
E/flutter (22117): , null)
Flutter version
• Flutter version 2.10.4 at C:\flutterSDKs\flutter_2.10.4
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c860cba910 (3 months ago), 2022-03-25 00:23:12 -0500
• Engine revision 57d3bac3dd
• Dart version 2.16.2
• DevTools version 2.9.2
Related
I encountered this error but I got no luck in finding a solution on this. Any idea on how I can resolve or at least try to understand what is the issue? Thanks!
E/flutter (18634): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: The Android view returned from PlatformView#getView() was already added to a parent view.
E/flutter (18634): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:238)
E/flutter (18634): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/flutter (18634): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/flutter (18634): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (18634): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (18634): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (18634): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (18634): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (18634): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (18634): at android.os.Looper.loopOnce(Looper.java:226)
E/flutter (18634): at android.os.Looper.loop(Looper.java:313)
E/flutter (18634): at android.app.ActivityThread.main(ActivityThread.java:8751)
E/flutter (18634): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (18634): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/flutter (18634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/flutter (18634): , null, null)
E/flutter (18634): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter (18634): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter (18634): <asynchronous suspension>
E/flutter (18634): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1146:18)
E/flutter (18634): <asynchronous suspension>
E/flutter (18634): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:792:5)
E/flutter (18634): <asynchronous suspension>
I tried to check the layout explorer but I haven't see any PlatformView so I'm stuck.
I have a method thats called to load models but seems to crash every time I call it, I followed the documentation for it I believe so I dont understand why.
Future loadModel() async {
await FirebaseModelDownloader.instance
.getModel(
"Breed-Detector",
FirebaseModelDownloadType.latestModel,
FirebaseModelDownloadConditions(
iosAllowsCellularAccess: true,
iosAllowsBackgroundDownloading: false,
androidChargingRequired: false,
androidWifiRequired: false,
androidDeviceIdleRequired: false,
))
.then((customModel) async {
final localModelPath = customModel.file;
Tflite.close();
String res;
res = (await Tflite.loadModel(
model: localModelPath.toString(), labels: "assets/labels.txt"))!;
print("Models Loading status: ${res}");
});
}
I get the error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Failed to load model, flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Breed-Detector/0', java.io.FileNotFoundException: flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Breed-Detector/0'
but I have the model uploaded
tried uploading a separate model and that seemed to try and download it at first but failed again.
/ModelFileDownloadSer( 7365): Need to download a new model.
D/ModelFileDownloadSer( 7365): Schedule a new downloading task: 64
D/ModelFileDownloadSer( 7365): Model downloaded successfully
D/ModelFileDownloadSer( 7365): Moving downloaded model from external storage to destination folder.
D/ModelFileDownloadSer( 7365): Moved the downloaded model to destination folder successfully: /data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds
E/flutter ( 7365): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Failed to load model, flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds/0', java.io.FileNotFoundException: flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds/0'
E/flutter ( 7365): at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
E/flutter ( 7365): at android.content.res.AssetManager.openFd(AssetManager.java:898)
E/flutter ( 7365): at sq.flutter.tflite.TflitePlugin.loadModel(TflitePlugin.java:210)
E/flutter ( 7365): at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:98)
E/flutter ( 7365): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter ( 7365): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 7365): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 7365): at android.os.Looper.loop(Looper.java:223)
E/flutter ( 7365): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter ( 7365): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 7365): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter ( 7365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 7365): , null)
TFLite (movenet/multipose/lightning/tflite/float16)
I have loaded the model successfully but whenever I tried to run it... it just crashes the
app.
here is the code for loading and running the model:
Future loadModel() async {
try {
res = await Tflite.loadModel(
model:
"assets/lite-model_movenet_multipose_lightning_tflite_float16_1.tflite",
);
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> model loaded: " + res.toString());
} catch (e) {
print(e);
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Failed to load model.');
} }
Future poseNet(File image) async {
int startTime = new DateTime.now().millisecondsSinceEpoch;
var output = await Tflite.runPoseNetOnImage(
threshold: 0.7,
path: image.path,
numResults: 5,
nmsRadius: 15
);
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> recognitions: ${output}');
setState(() {
_recognitions = output!;
});
int endTime = new DateTime.now().millisecondsSinceEpoch;
print(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Inference took ${endTime - startTime}ms ");}
here are the logs:
I/tflite (11904): Initialized TensorFlow Lite runtime.
I/flutter (11904): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> model loaded: success
W/System (11904): A resource failed to call close.
D/EGL_emulation(11904): eglCreateContext: 0xead612c0: maj 2 min 0 rcv 2
E/flutter (11904): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(Failed to run model, length=3; index=3, java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
E/flutter (11904): at sq.flutter.tflite.TflitePlugin.initPoseNet(TflitePlugin.java:1262)
E/flutter (11904): at sq.flutter.tflite.TflitePlugin$RunPoseNet.<init>(TflitePlugin.java:1290)
E/flutter (11904): at sq.flutter.tflite.TflitePlugin.runPoseNetOnImage(TflitePlugin.java:1217)
E/flutter (11904): at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:179)
E/flutter (11904): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (11904): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:178)
E/flutter (11904): at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java:206)
E/flutter (11904): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$6ZD1MYkhaLxyPjtoFDxe45u43DI.run(Unknown Source:12)
E/flutter (11904): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (11904): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (11904): at android.os.Looper.loop(Looper.java:223)
E/flutter (11904): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter (11904): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (11904): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter (11904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (11904): , null)
E/flutter (11904): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (11904): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (11904): <asynchronous suspension>
E/flutter (11904): #2 Tflite.runPoseNetOnImage (package:tflite/tflite.dart:350:12)
E/flutter (11904): <asynchronous suspension>
E/flutter (11904): #3 _SelectImageState.poseNet (package:model_ui/main/select_image.dart:105:18)
E/flutter (11904): <asynchronous suspension>
E/flutter (11904):
any help will be appreciated!
thank you!
I'm not an expert. But tflite plugin is out of date. You should try your luck with the tflite_flutter, which is also a bit outdated. But worked for me.
Permission to read External Storage is Granted. I am trying to read the path of files in a folder and if the path contains ".mp4" then make an image thumbnail from the video.
_mediaList the list of paths of all the files in the folder.
sample-path is like storage/emulated/0/StatusSaver/Downloads/469a14c6f26e47968b322b9d08ebe2b0.mp4
_mediaList.forEach((element) async {
if (element.path.contains(".mp4")) {
print("Video Status");
await VideoThumbnail.thumbnailData(
video: element.path,
imageFormat: ImageFormat.JPEG,
maxWidth:
128,
quality: 25,
).then((value) {
StatusList.insert(0, {
"type": StatusType.video,
"path": element.path,
"thumbnail": value
});
});
}
Error is like this
I/flutter (18331): PermissionStatus.granted
D/ThumbnailPlugin(18331): buildThumbnailData( format:0, maxh:0, maxw:128, timeMs:0, quality:25 )
W/System.err(18331): java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
W/System.err(18331): at android.media.MediaMetadataRetriever._setDataSource(Native Method)
W/System.err(18331): at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:103)
W/System.err(18331): at xyz.justsoft.video_thumbnail.VideoThumbnailPlugin.createVideoThumbnail(VideoThumbnailPlugin.java:205)
W/System.err(18331): at xyz.justsoft.video_thumbnail.VideoThumbnailPlugin.buildThumbnailData(VideoThumbnailPlugin.java:116)
W/System.err(18331): at xyz.justsoft.video_thumbnail.VideoThumbnailPlugin.access$100(VideoThumbnailPlugin.java:37)
W/System.err(18331): at xyz.justsoft.video_thumbnail.VideoThumbnailPlugin$1.run(VideoThumbnailPlugin.java:77)
W/System.err(18331): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(18331): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(18331): at java.lang.Thread.run(Thread.java:919)
E/flutter (18331): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method data on channel video_thumbnail)
E/flutter (18331): #0 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:156
E/flutter (18331): <asynchronous suspension>
E/flutter (18331): #1 VideoThumbnail.thumbnailData
package:video_thumbnail/video_thumbnail.dart:67
E/flutter (18331): <asynchronous suspension>
E/flutter (18331): #2 FileUtils.readSavedStatusFolder.<anonymous closure>
package:statussaver/model/file_utils.dart:53
E/flutter (18331): <asynchronous suspension>
E/flutter (18331):
So, The issue was with the path going into the thumbnailData.
I just had to add a "/" at the starting of the path.
As without "/", it was able to read the videos.
I'm stuck on how I would implement dart::ffi in Flutter, specifically the hello_world example.
Starting with the basic flutter create project (and an already compiled hello_world.dll) just trying:
void main() {
final dylib = ffi.DynamicLibrary.open('hello_world.dll');
final HelloWorld hello = dylib
.lookup<ffi.NativeFunction<hello_world_func>>('hello_world')
.asFunction();
hello();
runApp(MyApp());
}
leads to:
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
package:testing_flutter/main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:61913/wRTGFN76kik=/ws
E/flutter (11980): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library (dlopen failed: library "hello_world.dll" not found)
E/flutter (11980): #0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
E/flutter (11980): #1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
E/flutter (11980): #2 main
package:testing_flutter/main.dart:8
E/flutter (11980): #3 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:140:25)
E/flutter (11980): #4 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (11980): #5 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (11980): #6 _runZoned (dart:async/zone.dart:1788:10)
E/flutter (11980): #7 runZonedGuarded (dart:async/zone.dart:1776:12)
E/flutter (11980): #8 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:133:5)
E/flutter (11980): #9 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (11980): #10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (11980):
Would I also need a .dylib version, something like what's in the example?
var libraryPath =
path.join(Directory.current.path, 'hello_library', 'libhello.so');
if (Platform.isMacOS)
libraryPath =
path.join(Directory.current.path, 'hello_library', 'libhello.dylib');
if (Platform.isWindows)
libraryPath = path.join(
Directory.current.path, 'hello_library', 'Debug', 'hello.dll');