Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

🚀 Performance, usability & playback improvements #27

Merged
merged 26 commits into from
Mar 4, 2021
Merged

Conversation

alexmercerind
Copy link
Owner

@alexmercerind alexmercerind commented Mar 1, 2021

This PR contains major rewrite of the plugin to improve performance, add new features & more control on playback of audio.

Plugin Changes:

  • Now you can listen to playback events using stream (a broadcast stream) inside AudioPlayer. This was a great problem in earlier version as one always needs to trigger UI updates whenever playback progresses, ends etc.
  • One of the big problems in earlier version was that there was no way to detect if an audio playback has ended after completion. Resulting in issues like Play songs one after another  #25 & Repeat sound #26. Now audio.isCompleted stores bool if an audio has ended, same can be accessed from stream.
  • Added a new Queue class to play audio files sequentially, without having to deal with things like audio.isCompleted etc. manually.
  • Added methods to deal with Queue or repeat playback etc.
  • Now you can provide any random id while creating new instance of AudioPlayer, this was a big problem earlier as new id had to be consecutive to earlier one.
  • Now you can access same instance of AudioPlayer even if you make new constructor, by providing same id.
  • Now asset files can be played & loaded into AudioPlayer using load method.
    • AudioSource class has two static methods
      • AudioSource.fromFile to load an audio file.
      • AudioSource.fromAsset to load an audio asset.
  • Now audio field stores Audio object, inside the AudioPlayer class & contains following fields to get information about current playback.
    • file: Current loaded File.
    • isPlaying : Whether file is playing.
    • isCompleted: Whether file is ended playing.
      • By default once playback is ended, stop method is called & AudioPlayer is reverted to initial configuration.
    • isStopped: Whether file is loaded.
    • position: Position of current playback in Duration.
    • duration: Duration of current file in Duration.
  • Now contructor of AudioPlayer no longer calls async methods, which could result in false assertions.

Native Code Changes:

  • Now ma_resource_manager is used from miniaudio_engine with MA_DATA_SOURCE_FLAG_STREAM flag.
    • This will improve general performance during playback, as whole file will not be loaded into memory.
  • Structure of code improved & separated into various files & classes.
  • Now device handling is present in an entirely separate class AudioDevices.
  • Improvements to how methods are identified & called in method channel. flutter_types.hpp improves code readability.
  • Other bug-fixes that randomly caused termination after assertion are also fixed to an extent.

Progress on Platforms

Bringing these changes to Windows will take barely few hours.

windows

linux

- Added separate Method class to get arguments & return values through method channels easily.

- Now using std::map instead of std::vector for handling mutiple players.
- Audio Devices class now has following static methods to deal with playback.

- getAll
- getDefault
- getAllMap
- Now plugin uses miniaudio_engine.
- Added AudioPlayers class with single method to create new or get existing player.
- Using std::map instead of std::vector to create a new player for any particular ID.
- General improvements to structure of code.
- Instanciating ma_resource_manager with MA_DATA_SOURCE_FLAG_STREAM flag.
- Fixed randomly occuring segmentation fault.
- No longer async method will be called from Dart's class constructor.
- Playback now stops once the track is finished & informs Dart side code.
- Now pause event is also recognised inside the broadcast stream. (Might get improved in future)
- Now stop method no longer, causes termination on false assertion.
- Added isStopped attribute to Audio objects to indicate if a file is loaded.
@alexmercerind alexmercerind merged commit ebf6294 into master Mar 4, 2021
@alexmercerind alexmercerind deleted the vnext branch March 4, 2021 15:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant