IAmKio / ocarina

Flutter plugin to play local audio files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ocarina

Ocarina is a simple and easy to use audio package for Flutter. Its goal is to support audio play from local file (from assets, or filesystem), And to support it across all platforms that Flutter runs.

Right now, we only support mobile (Android and iOS) and will eventually supporting Web and Desktop (Linux, MacOS and Windows).

How to use

Using a file on your assets

final player = OcarinaPlayer(
  asset: 'assets/Loop-Menu.wav',
  package: 'my_package_name',
  loop: true,
  volume: 0.8,
);

await player.load();

Using a file on the device filesystem

final player = OcarinaPlayer(
  filePath: '/SomeWhere/On/The/Device/Loop-Menu.wav',
  loop: true,
  volume: 0.8,
);

await player.load();

Docs

List of all available methods on the player instance

play

Starts playing

pause

Pauses playback

resume

Resume when playback if it was previously paused

stop

Stops the playback, it can be started again by calling play again.

seek(Duration)

Moves the playback postion to the passed Duration

position

Retrieves playback position in milliseconds.

updateVolume(double)

Updates the volume, must be a value between 0 and 1

dispose

Clears the loaded resources in memory, to use the instance again a subsequent call on the load method is required

iOS Delegation

This feature was developed in concert with the development of the AVAudioEngineDevice in twilio_programmable_video version 0.6.4 to address the issue in iOS in which the operating system gives priority to the VoiceProcessingIO Audio Unit, causing output volume of audio files from ocarina to be significantly diminished when used while a call is underway. While this was the reason for introducing this feature to ocarina, it was designed to be agnostic to the nature of the delegate. It is strongly advised that if you are writing your own delegate for iOS, that you seek to mirror the behaviour of ocarina itself as much as is possible so as to reduce the possibility of inconsistent behaviour across platforms.

If you found your way here because ocarina was recommended by twilio_programmable_video, the following modification to your AppDelegate will setup the AVAudioEngineDevice as the delegate for ocarina:

  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

    let audioDevice = AVAudioEngineDevice()
    SwiftTwilioProgrammableVideoPlugin.audioDevice = audioDevice
    SwiftOcarinaPlugin.useDelegate(
        load: audioDevice.addMusicNode,
        dispose: audioDevice.disposeMusicNode,
        play: audioDevice.playMusic,
        pause: audioDevice.pauseMusic,
        resume: audioDevice.resumeMusic,
        stop: audioDevice.stopMusic,
        volume: audioDevice.setMusicVolume,
        seek: audioDevice.seekPosition,
        position: audioDevice.getPosition
    )

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

About

Flutter plugin to play local audio files

License:MIT License


Languages

Language:Swift 40.7%Language:Dart 28.5%Language:Kotlin 26.3%Language:Ruby 2.7%Language:Objective-C 1.9%