Skip to content

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

Notifications You must be signed in to change notification settings

jasimameen/on_audio_query

 
 

Repository files navigation

on_audio_query

Pub.dev Languages Platforms

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

Help:

Topics:

Platforms:

Query methods

Methods Android IOS
queryAudios ✔️ ✔️
queryAlbums ✔️ ✔️
queryArtists ✔️ ✔️
queryPlaylists ✔️ ✔️
queryGenres ✔️ ✔️
queryArtwork ✔️ ✔️
queryDeviceInfo ✔️ ✔️

Observer methods

Methods Android IOS
observeAudios ✔️ ✔️
observeAlbums ✔️ ✔️
observeArtists ✔️ ✔️
observePlaylists ✔️ ✔️
observeGenres ✔️ ✔️

✔️ -> Supported
❌ -> Not Supported

See all platforms methods support

How to Install:

Add the following code to your pubspec.yaml:

dependencies:
  on_audio_query: 3.0.0-beta.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.

Overview:

All types of methods on this plugin:

Query methods

Methods Parameters Return
queryAudios (MediaFilter, isAsset) List<AudioModel>
queryAlbums (MediaFilter, isAsset) List<AlbumModel>
queryArtists (MediaFilter, isAsset) List<ArtistModel>
queryPlaylists (MediaFilter, isAsset) List<PlaylistModel>
queryGenres (MediaFilter, isAsset) List<GenreModel>
queryArtwork (id, type, format, size) Uint8List?

Observer methods

Methods Parameters Return
observeAudios (MediaFilter) List<AudioModel>
observeAlbums (MediaFilter) List<AlbumModel>
observeArtists (MediaFilter) List<ArtistModel>
observePlaylists (MediaFilter) List<PlaylistModel>
observeGenres (MediaFilter) List<GenreModel>

Playlist methods

Methods Parameters Return
createPlaylist (playlistName) int
removePlaylist (playlistId) bool
addToPlaylist (playlistId, audioId) bool
removeFromPlaylist (playlistId, audioId) bool
renamePlaylist (playlistId, newName) bool
moveItemTo (playlistId, from, to) bool

Permissions/Device methods

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

Others methods

Methods Parameters Return
scanMedia (path) bool
observersStatus ObserversModel

Artwork Widget

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

See more: QueryArtworkWidget

Examples:

OnAudioQuery

final OnAudioQuery _audioQuery = OnAudioQuery();

Query methods:

  • queryAudios();
  • queryAlbums();
  • queryArtists();
  • queryPlaylists();
  • queryGenres().
  someName() async {
    // Query Audios
    List<AudioModel> audios = await _audioQuery.queryAudios();

    // Query Albums
    List<AlbumModel> albums = await _audioQuery.queryAlbums();
  }

scanMedia

You'll use this method when updating a media from storage. This method will update the media 'state' and Android MediaStore will be able to know this 'state'.

  someName() async {
    OnAudioQuery _audioQuery = OnAudioQuery();
    File file = File('path');
    try {
      if (file.existsSync()) {
        file.deleteSync();
        _audioQuery.scanMedia(file.path); // Scan the media 'path'
      }
    } catch (e) {
      debugPrint('$e');
    }
  }

queryArtwork

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

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

Gif Examples:

Audios Albums Playlists Artists

LICENSE:

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 47.0%
  • Kotlin 24.1%
  • Swift 19.0%
  • C++ 5.2%
  • CMake 2.7%
  • HTML 0.9%
  • Other 1.1%