setAsset method

Future<Duration?> setAsset(
  1. String assetPath, {
  2. String? package,
  3. bool preload = true,
  4. Duration? initialPosition,
})

Convenience method to set the audio source to an asset, preloaded by default, with an initial position of zero by default.

For assets within the same package, this is equivalent to:

setAudioSource(AudioSource.uri(Uri.parse('asset:///$assetPath')),
    initialPosition: Duration.zero, preload: true);

If the asset is to be loaded from a different package, the package parameter must be given to specify the package name.

See setAudioSource for a detailed explanation of the options.

Implementation

Future<Duration?> setAsset(
  String assetPath, {
  String? package,
  bool preload = true,
  Duration? initialPosition,
}) =>
    setAudioSource(
      AudioSource.asset(assetPath, package: package),
      initialPosition: initialPosition,
      preload: preload,
    );