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

LucJosin/on_audio_query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

on_audio_query

Pub.dev Platforms Languages

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

Any problem? Issues
Any suggestion? Pull request

Topics:

Platforms:

Methods Android IOS Web
querySongs βœ”οΈ βœ”οΈ βœ”οΈ
queryAlbums βœ”οΈ βœ”οΈ βœ”οΈ
queryArtists βœ”οΈ βœ”οΈ βœ”οΈ
queryPlaylists βœ”οΈ βœ”οΈ ❌
queryGenres βœ”οΈ βœ”οΈ βœ”οΈ
queryAudiosFrom βœ”οΈ βœ”οΈ βœ”οΈ
queryWithFilters βœ”οΈ βœ”οΈ βœ”οΈ
queryArtwork βœ”οΈ βœ”οΈ βœ”οΈ
createPlaylist βœ”οΈ βœ”οΈ ❌
removePlaylist βœ”οΈ ❌ ❌
addToPlaylist βœ”οΈ βœ”οΈ ❌
removeFromPlaylist βœ”οΈ ❌ ❌
renamePlaylist βœ”οΈ ❌ ❌
moveItemTo βœ”οΈ ❌ ❌
checkAndRequest βœ”οΈ βœ”οΈ ❌
permissionsRequest βœ”οΈ βœ”οΈ ❌
permissionsStatus βœ”οΈ βœ”οΈ ❌
queryDeviceInfo βœ”οΈ βœ”οΈ βœ”οΈ
scanMedia βœ”οΈ ❌ ❌

βœ”οΈ -> Supported
❌ -> Not Supported

See all platforms methods support

Installation:

Add the following code to your pubspec.yaml:

dependencies:
  on_audio_query: ^2.9.0

Request Permission:

Android:

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

<manifest>
  
  <!-- Android 12 or below  -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

  <!-- Android 13 or greater  -->
  <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
  <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
  <uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>

</manifest>

IOS:

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

<dict>

	<key>NSAppleMusicUsageDescription</key>
	<string>$(PROJECT_NAME) requires access to media library</string>

</dict>

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:

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:

Songs Albums Playlists Artists

LICENSE: