on_audio_query

Pub.dev Platform Flutter Kotlin

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

Translations:

NOTE: Feel free to help with readme translations

Topics:

Gif Examples:

SongsAlbumsPlaylistsArtists

How to Install:

Add the following code to your pubspec.yaml:

dependencies:
  on_audio_query: ^1.0.5

Request Permission:

If you want to use the built-in request permission, will need 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>

Some Features:

  • Optional and Built-in storage READ and WRITE permission request
  • Get all audios and audios classified with is_music.
  • 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 method to edit audio tag.
  • Create methods for IOS.
  • 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:

MethodsParametersReturn
querySongs(SortType, OrderType, UriType,RequestPermission)List<SongModel>
queryAudio(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>
queryAudiosOnlyNew(Type, Where, AudiosOnlyType, RequestPermission)List<SongModel>
queryWithFiltersNew(ArgsVal, WithFiltersType, Args, RequestPermission)List<dynamic>
queryArtworks(Id, Type, Format, Size, RequestPermission)Uint8List
createPlaylist(PlaylistName, RequestPermission)bool
removePlaylist(PlaylistId, RequestPermission)bool
addToPlaylistNT-BG(PlaylistId, AudioId, RequestPermission)bool
removeFromPlaylistNT(PlaylistId, AudioId, RequestPermission)bool
renamePlaylist(PlaylistId, NewName, RequestPermission)bool
moveItemToNT(PlaylistId, From, To, RequestPermission)bool
permissionsRequest(retryRequest)bool
permissionsStatusbool
getDeviceSDKint
getDeviceReleaseString
getDeviceCodeString

Note: Some query methods require the SortType and RequestPermisson, by default, will be set DEFAULT and false See all defaults sorttypes in Examples

NT -> Need Tests
BG -> Bug on Android 10/Q

Examples:

querySongs

  someName() async {
    //DEFAULT: SongSortType.TITLE, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().querySongs();
  }

queryAlbums

  someName() async {
    //DEFAULT: AlbumSortType.ALBUM, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().queryAlbums();
  }

queryArtists

  someName() async {
    //DEFAULT: ArtistSortType.ARTIST, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().queryArtists();
  }

queryPlaylists

  someName() async {
    //DEFAULT: PlaylistSortType.NAME, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().queryPlaylists();
  }

queryGenres

  someName() async {
    //DEFAULT: GenreSortType.NAME, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().queryGenres();
  }

queryArtworks

Note: Only in Android >= Q/10

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

  //Or you can use a basic and custom Widget
  Widget someOtherName() async {
    var version = await OnAudioQuery().getDeviceSDK();
    if (version >= 29) {
      return QueryArtworkWidget(
        id: SongId, 
        type: ArtworkType.AUDIO
      );
    }
    return Icon(Icons.image_not_supported)
  }

queryAudiosOnly

Note: Some Types only exist in Android >= Q/10, if you try call them Android below Q/10 will return all types.
See more in Documentation

  someName() async {
    //DEFAULT: SongSortType.TITLE, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().queryAudiosOnly(AudiosOnlyType.IS_AUDIOBOOK);
  }

  someOtherName() async {
    //DEFAULT: SongSortType.TITLE, OrderType.ASC_OR_SMALLER and false
    var something = await OnAudioQuery().queryAudiosOnly(AudiosOnlyType.IS_PODCAST);
  }

queryWithFilters

Note: Args are defined with [dynamic] but will only work if you use correct Types.
See more in Documentation -> Enums

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

LICENSE:

Libraries

on_audio_query