tiagohm / libao

A Dart wrapper for the libao library to output audio using a simple API on a wide variety of platforms.
https://pub.dev/packages/libao
MIT License
24 stars 3 forks source link

Unhandled Exception: Null check operator used on a null value #5

Open UNIcodeX opened 3 years ago

UNIcodeX commented 3 years ago

When calling Libao.open();, I'm getting the message in the title, on Windows 10.

following the stack trace takes me to this

 /// Loads the libao library.
  factory Libao.open([String? /*?*/ path]) {
    if (path != null && path.isNotEmpty) {
      // nada.
    } else if (Platform.isLinux) {
      path = '/usr/lib/x86_64-linux-gnu/libao.so.4';
    }

    final lib = DynamicLibrary.open(path!);  # <<<<
    return Libao._(lib);
  }
maks commented 3 years ago

Hmm, yes I probably should have changed that code to be a bit better when I did the port to null-safety. But how are you passing in the path to the libao dll ? The exception is occurring because the path is null.

sleepreading commented 2 years ago

Same Problem! Environment:

Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 18116933e7 (9 weeks ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4

change code Libao.open() to Libao.open(""), will cause this exception:

Invalid argument(s): Failed to load dynamic library '': dlopen failed: can't read file "/data/app/......-w8jcxgmbluIa0EgCRsGHow==/lib/arm64": Is a directory stack:#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
I/flutter (10825): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
maks commented 2 years ago

@sleepreading ok but where is the libao shared library that you are trying to use located? The whole point is that you do need to supply the path the library. It would help if you could also mention what OS/platform you are trying to run this on?

sleepreading commented 2 years ago

@maks Sorry for my poor English, this is my Android Phone:

Honor 10 - COL AL10
System: EMUI
Android Version: 10
Kernel-Version: 4.14.116
CPU: HiSilicon Kirin 970
RAM: 6GB

I used your demo code: final ao = Libao.open(); and this will cause the problem as mentioned by @UNIcodeX above: Null check operator used on a null value, so I change open() to open(''), and this will cause a new exception as I mentioned above.

maks commented 2 years ago

No worries and no need to apologise. Ah I see what you are trying to do now. As far as I know Libao only supports some desktop operating systems and does not really support Android. You can see the list of all the platforms Libao supports on thier homepage. However it does seem that some people have experimented with getting it compiled for Android but from what I can see it is not fully functional.

Depending on what audio playback functionality you need, you may be better off looking to use something like just_audio.

sleepreading commented 2 years ago

Thanks! I must admit that this library is awesome because just_audio and audioplayers are both non-supported for playBytes()(They only support playing raw audio bytes on android), But your library supports almost every platform(except web). Turns out, it's really hard to play raw audio bytes(which I received from a server using HTTP or grpc) on all platforms.

maks commented 2 years ago

@sleepreading I agree, I really like this package too, but it doesn't change that the underlying libao library does not support Android. I maybe working on a similar Dart FFI package for Android's Oboe library, so I'll make sure to mention it here if I do get it published in the future.