on_audio_query 1.1.3 on_audio_query: ^1.1.3 copied to clipboard
Flutter Plugin used to query audios/songs infos [title, artist, album, etc..] 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_edit - Used to edit audio metadata.
- on_audio_room - Used to store audio [Favorites, Most Played, etc..].
Translations: #
NOTE: Feel free to help with readme translations
Topics: #
Gif Examples: #
Songs | Albums | Playlists | Artists |
How to Install: #
Add the following code to your pubspec.yaml
:
dependencies:
on_audio_query: ^1.1.3
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
andWRITE
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 folders and 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.
- 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:
Methods | Parameters | Return |
---|---|---|
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> |
queryAudiosOnly |
(Type, Where, AudiosOnlyType, RequestPermission) |
List<SongModel> |
querySongsBy |
(SongsByType, Values, UriType, RequestPermission) |
List<SongModel> |
queryWithFilters |
(ArgsVal, WithFiltersType, Args, RequestPermission) |
List<dynamic> |
queryArtworks |
(Id, Type, Format, Size, RequestPermission) |
Uint8List? |
queryFromFolder |
(Path, SortType, OrderType, UriType, RequestPermission) . |
List<SongModel> |
queryAllPath |
List<String> |
|
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 |
permissionsRequest |
(retryRequest) |
bool |
permissionsStatus |
bool |
|
queryDeviceInfo |
DeviceModel |
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, UriType.EXTERNAL 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 works 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. See example QueryArtworkWidget
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);
}
QueryArtworkWidget
Now [QueryArtworkWidget]
support all Android versions.
Widget someOtherName() async {
DeviceModel deviceInfo = await OnAudioQuery().queryDeviceInfo();
return QueryArtworkWidget(
id: SongId,
type: ArtworkType.AUDIO,
artwork: songList[index].artwork,
deviceSDK: device.sdk,
);
}
See more in QueryArtworkWidget