Flutter Plugin used to query audios/songs infos from device storage

on_audio_query

on_audio_query is a Flutter Plugin used to query audios/songs infos [title, artist, album, etc..] from device storage.

Help:

Any problem? Issues

Any suggestion? Pull request

Extensions:

  • on_audio_room - Used to store audio [Favorites, Most Played, etc..].

Gif Examples:

Songs Albums Playlists Artists

Platforms:

Methods Android IOS Web
querySongs ✔️ ✔️ ✔️
queryAlbums ✔️ ✔️ ✔️
queryArtists ✔️ ✔️ ✔️
queryPlaylists ✔️ ✔️
queryGenres ✔️ ✔️ ✔️
queryAudiosFrom ✔️ ✔️ ✔️
queryWithFilters ✔️ ✔️ ✔️
queryArtwork ✔️ ✔️ ✔️
createPlaylist ✔️ ✔️
removePlaylist ✔️
addToPlaylist ✔️ ✔️
removeFromPlaylist ✔️
renamePlaylist ✔️
moveItemTo ✔️
permissionsRequest ✔️ ✔️
permissionsStatus ✔️ ✔️
queryDeviceInfo ✔️ ✔️ ✔️

✔️ -> Supported

❌ -> Not Supported

See all platforms methods support

How to Install:

Add the following code to your pubspec.yaml:

dependencies:
  on_audio_query: ^2.1.0

Request Permission:

Android:

To use this plugin add the following code to your AndroidManifest.xml

<manifest> ...

  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

</manifest>

IOS:

To use this plugin add the following code to your Info.plist

	<key>NSAppleMusicUsageDescription</key>
	<string>..Add a reason..</string>

Some Features:

  • Optional and Built-in storage READ and WRITE permission request
  • Get all audios/songs.
  • Get all albums and album-specific audios.
  • Get all artists and artist-specific audios.
  • Get all playlists and playlists-specific audios.
  • Get all genres and genres-specific audios.
  • Get all query methods with specific keys [Search].
  • Create/Delete/Rename playlists.
  • Add/Remove/Move specific audios to playlists.
  • Specific sort types for all query methods.

TODO:

  • Add better performance for all plugin.
  • Add support to Web/Windows/MacOs/Linux.
  • Option to remove songs.
  • Fix bugs.

How to use:

OnAudioQuery() // The main method to start using the plugin.

All types of methods on this plugin:

Query methods

Methods Parameters Return
querySongs (SortType, OrderType, UriType, RequestPermission) List<SongModel>
queryAlbums (SortType, OrderType, UriType, RequestPermission) List<AlbumModel>
queryArtists (SortType, OrderType, UriType, RequestPermission) List<ArtistModel>
queryPlaylists (SortType, OrderType, UriType, RequestPermission) List<PlaylistModel>
queryGenres (SortType, OrderType, UriType, RequestPermission) List<GenreModel>
queryAudiosFrom (Type, Where, RequestPermission) List<SongModel>
queryWithFilters (ArgsVal, WithFiltersType, Args, RequestPermission) List<dynamic>
queryArtwork (Id, Type, Format, Size, RequestPermission) Uint8List?

Playlist methods

Methods Parameters Return
createPlaylist (PlaylistName, RequestPermission) bool
removePlaylist (PlaylistId, RequestPermission) bool
addToPlaylist [NT-BG](PlaylistId, AudioId, RequestPermission) bool
removeFromPlaylist [NT](PlaylistId, AudioId, RequestPermission) bool
renamePlaylist (PlaylistId, NewName, RequestPermission) bool
moveItemTo [NT](PlaylistId, From, To, RequestPermission) bool

Permissions/Device methods

Methods Parameters Return
permissionsRequest (retryRequest) bool
permissionsStatus bool
queryDeviceInfo DeviceModel

Artwork Widget

Now [QueryArtworkWidget] support all Android versions.

  Widget someOtherName() async {
    return QueryArtworkWidget(
      id: SongId, 
      type: ArtworkType.AUDIO,
    );
  }

See more: QueryArtworkWidget

Abbreviations

[NT] -> Need Tests

[BG] -> Bug on Android 10/Q

Examples:

querySongs

  someName() async {
    // DEFAULT: 
    // SongSortType.TITLE, 
    // OrderType.ASC_OR_SMALLER,
    // UriType.EXTERNAL, 
    List<SongModel> something = await OnAudioQuery().querySongs();
  }

queryAlbums

  someName() async {
    // DEFAULT: 
    // AlbumSortType.ALBUM, 
    // OrderType.ASC_OR_SMALLER 
    List<AlbumModel> something = await OnAudioQuery().queryAlbums();
  }

queryArtists

  someName() async {
    // DEFAULT: 
    // ArtistSortType.ARTIST, 
    // OrderType.ASC_OR_SMALLER 
    List<ArtistModel> something = await OnAudioQuery().queryArtists();
  }

queryPlaylists

  someName() async {
    // DEFAULT: 
    // PlaylistSortType.NAME, 
    // OrderType.ASC_OR_SMALLER 
    List<PlaylistModel> something = await OnAudioQuery().queryPlaylists();
  }

queryGenres

  someName() async {
    // DEFAULT: 
    // GenreSortType.NAME, 
    // OrderType.ASC_OR_SMALLER 
    List<GenreModel> something = await OnAudioQuery().queryGenres();
  }

queryArtwork

Note: Only works in Android >= Q/10

  someName() async {
    // DEFAULT: ArtworkFormat.JPEG, 200 and false
    Uint8List something = await OnAudioQuery().queryArtwork(
        SongId, 
        ArtworkType.AUDIO, 
        ...,
      );
  }

Or you can use a basic and custom Widget.
See example QueryArtworkWidget

queryWithFilters

  someName() async {
    // DEFAULT: Args.TITLE and false
    // ArgsTypes: AudiosArgs, AlbumsArgs, PlaylistsArgs, ArtistsArgs, GenresArgs
    List<dynamic> something = await OnAudioQuery().queryWithFilters(
        "Sam Smith", 
        WithFiltersType.ARTISTS,
      );

    // After getting the result from [queryWithFilters], convert this list using:
    List<TypeModel> convertedList = something.toTypeModel();

    // Example:
    List<SongModel> convertedSongs = something.toArtistModel(); 
  }

GitHub

https://github.com/LucasPJS/on_audio_query