import ‘dart:ffi’ as ffi;
// Utilities for working with ffi like String
import ‘package:ffi/ffi.dart’;
// Create a typedef with the FFI type signature of the C function.
// Commonly used types defined by dart:ffi library include Double, Int32, NativeFunction, Pointer, Struct, Uint8, and Void.
typedef play_once_func = ffi.Void Function(ffi.Pointer);
// Create a typedef for the variable that you’ll use when calling the C function.
typedef PlayOnce = void Function(ffi.Pointer);
void play_music() {
ffi.DynamicLibrary dylib = ffi.DynamicLibrary.open(‘libplay_once.dylib’);
// Get a reference to the C function, and put it into a variable. This code uses the typedefs defined in steps 2 and 3, along with the dynamic library variable from step 4.
final PlayOnce play_once = dylib
.lookup<ffi.NativeFunction<play_once_func>>(‘play_once’)
.asFunction();