on_audio_query
is a Flutter Plugin used to query audios/songs 🎶 infos [title, artist, album, etc..] from device storage.
- Docs: Pub.dev
- Any problem? Issues
- Any suggestion? Pull request
Methods | Android | IOS |
---|---|---|
queryAudios |
✔️ |
✔️ |
queryAlbums |
✔️ |
✔️ |
queryArtists |
✔️ |
✔️ |
queryPlaylists |
✔️ |
✔️ |
queryGenres |
✔️ |
✔️ |
queryArtwork |
✔️ |
✔️ |
queryDeviceInfo |
✔️ |
✔️ |
Methods | Android | IOS |
---|---|---|
observeAudios |
✔️ |
✔️ |
observeAlbums |
✔️ |
✔️ |
observeArtists |
✔️ |
✔️ |
observePlaylists |
✔️ |
✔️ |
observeGenres |
✔️ |
✔️ |
✔️ -> Supported
❌ -> Not Supported
See all platforms methods support
Add the following code to your pubspec.yaml
:
dependencies:
on_audio_query: 3.0.0-beta.0
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>
To use this plugin add the following code to your Info.plist
<key>NSAppleMusicUsageDescription</key>
<string>..Add a reason..</string>
- Optional and Built-in storage
READ
andWRITE
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.
All types of methods on this plugin:
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? |
Methods | Parameters | Return |
---|---|---|
observeAudios |
(MediaFilter) |
List<AudioModel> |
observeAlbums |
(MediaFilter) |
List<AlbumModel> |
observeArtists |
(MediaFilter) |
List<ArtistModel> |
observePlaylists |
(MediaFilter) |
List<PlaylistModel> |
observeGenres |
(MediaFilter) |
List<GenreModel> |
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 |
Methods | Parameters | Return |
---|---|---|
permissionsRequest |
(retryRequest) |
bool |
permissionsStatus |
bool |
|
queryDeviceInfo |
DeviceModel |
Methods | Parameters | Return |
---|---|---|
scanMedia |
(path) |
bool |
observersStatus |
ObserversModel |
Widget someOtherName() async {
return QueryArtworkWidget(
id: <audioId>,
type: ArtworkType.AUDIO,
);
}
See more: QueryArtworkWidget
final OnAudioQuery _audioQuery = OnAudioQuery();
- queryAudios();
- queryAlbums();
- queryArtists();
- queryPlaylists();
- queryGenres().
someName() async {
// Query Audios
List<AudioModel> audios = await _audioQuery.queryAudios();
// Query Albums
List<AlbumModel> albums = await _audioQuery.queryAlbums();
}
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');
}
}
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
Audios | Albums | Playlists | Artists |