flutter_audio_query 0.2.1

Flutter Audio Query #

A Flutter plugin, Android only at this moment, that allows you query for audio metadata info about artists, albums, songs audio files and genres available on device storage. All work is made using Android native MediaStore API with ContentResolver API and query methods run in background thread. AndroidX support it's OK!

Note: This plugin is under development, Works in Android devices only and some APIs are not available yet. Feedback, pull request, bug reports and suggestions are all welcome!

Feel free to help!

Example app included #

| | | |

Features #

  • Android permissions READ_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE built-in
  • Get all artists audio info available on device storage
  • Get artists available from a specific genre
  • Search for artists matching a name
  • Artist comes with some album Artwork cover if available
  • Get all albums info available on device storage
  • Get albums available from a specific artist
  • Get albums available from a specific genre
  • Search albums matching a name
  • Album artwork included if available
  • Get songs all songs available on device storage
  • Get songs from a specific album
  • Songs already comes with album artwork cover if available
  • Get availables genre.
  • Get all playlists available
  • Create new playlists
  • Remove playlist
  • Add songs to playlist
  • Remove song from playlist
  • Multiple sort types for Artist, Album, Song, Genre, Playlist.

TO DO #

  • Make this basic implementation for iOS.
  • Allow change playlist songs order
  • Streams support.
  • Improvements in background tasks.
  • More tests and probably bug fixes.

Usage #

To use this plugin, add flutter_audio_query as a dependency in your pubspec.yaml file. For example:

  dependencies:
    flutter_audio_query

API #

FlutterAudioQuery #

To get get audio files metadata info you just need FlutterAudioQuery object instance.

///you need include this file only.
import 'package:flutter_audio_query/flutter_audio_query.dart';
/// create a FlutterAudioQuery instance.
final FlutterAudioQuery audioQuery = FlutterAudioQuery();

Getting all artist available on device storage: #

List<ArtistInfo> artists = await audioQuery.getArtists(); // returns all artists available

artists.forEach( (artist){
      print(artist); /// prints all artist property values
    } );

Getting albums data: #

 /// getting all albums available on device storage
 List<AlbumInfo> albumList = await audioQuery.getAlbums();

/// getting all albums available from a specific artist
List<AlbumInfo> albums = await audioQuery.getAlbumsFromArtist(artist: artist);
    albums.forEach( (artistAlbum) {
      print(artistAlbum); //print all album property values
    });

Getting genre data #

/// getting all genres available
 List<GenreInfo> genreList = audioQuery.getGenres();

 genreList.foreach( (genre){
   /// getting all artists available from specific genre.
   await audioQuery.getArtistsFromGenre(genre: genre);

   /// getting all albums which appears on genre [genre].
   await audioQuery.getAlbumsFromGenre(genre: genre);

   /// getting all songs which appears on genre [genre]
   await audioQuery.getSongsFromGenre(genre: genre);
 } );

Getting songs data #

 /// getting all songs available on device storage
List<SongInfo> songs = await audioQuery.getSongs();

albumList.foreach( (album){
  /// getting songs from specific album
  audioQuery.getSongsFromAlbum(album: album);
 } );

Getting playlist data #

    /// getting all playlist available
    List<PlaylistInfo> playlist = await audioQuery.getPlaylists();

    /// Getting playlist songs
    List<SongInfo> songs = await audioQuery.getSongsFromPlaylist(playlist: playlist[0]);

    /// adding songs into a specific playlist
    PlaylistInfo updatedPlaylist = await playlist[0].addSong(song: songs[2] );

    //removing song from a specific playlist
    updatedPlaylist = await updatedPlaylist.removeSong(song: songs[2]);

Sorting queries #

You can also define a sort query constraint to get the data already sorted using sort enums.ArtistSortType, AlbumSortType, SongSortType, GenreSortType, PlaylistSortType.

    /// Getting albums sorted by most recent year first
    audioQuery.getAlbums(sortType: AlbumSortType.MOST_RECENT_YEAR )

    /// getting artists sorted by number of songs
    audioQuery.getArtits(sortType: ArtistSortType.MORE_TRACKS_NUMBER_FIRST);
    /// and more...

Searching #

You can search using search methods.

    ///searching for albums that title starts with 'a'
    List<AlbumInfo> albums = await audioQuery.searchAlbums(query "a");

    /// searching for songs that title starts with 'la'
    List<SongInfo> songs = await audioQuery.searchSongs(query: "la");

Contributing #

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License #

MIT LICENSE

0.2.1 #

  • Breaking change: Now getSongsFromAlbum don't take an ArtistInfo in parameter. If you want to get all songs from an specific album you can use getSongsFromAlbum method. But if you want to get all songs from an specific album from an specific artist do this with getSongsFromArtistAlbum method.

  • Now is possible fetch songs by ID's with getSongsById method.

  • Now is possible fetch albums by ID's with getAlbumsById method.

0.1.1 #

  • Bug fix: Before this fix, getGenre method was returning genres that has no one data related, no one artist, album or a song. Now getGenre calls return only genres which at least one artist, album or song appears.

0.1.0 #

  • Documentation completed

0.0.1 #

  • Initial Release

example/README.md

flutter_audio_query_example #

Demonstrates how to use the flutter_audio_query plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_audio_query: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_audio_query/flutter_audio_query.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8