on_audio_room

Pub.dev Platform Flutter Kotlin

on_audio_room is a Flutter Plugin used to create a database for storage audio sections Favorites, Internal Playlists, Most Played, etc....

This Plugin works as a "extension" to on_audio_query and some methods will require it.

Help:

Any problem? Issues
Any suggestion? Pull request

Translations:

NOTE: Feel free to help with readme translations

Topics:

How to Install:

Add the following code to your pubspec.yaml:

dependencies:
  on_audio_room: ^1.0.1+1

Some Features:

  • Favorites section
  • Last Played section
  • Most Played section
  • Internal playlists section

TODO:

  • Add better performance for all plugin.
  • Add [Features].
  • Create methods for IOS.
  • Fix bugs.

How to use:

OnAudioRoom() // The main method to start using the plugin.

All types of methods on this plugin:

Database methods

Methods Parameters Return
setDatabaseName (String) bool
setDatabaseLimit (int) bool
getDatabaseName String
getDatabaseLimit int
getDatabaseStatus bool
resetDatabaseName bool
resetDatabaseLimit bool
resetAllDatabase bool
closeDatabase bool

Global methods

Methods Parameters Return
addTo (RoomType, Entity, PlaylistId?) int
addAllTo (RoomType, Entity, PlaylistId?) List<int>
deleteFrom (RoomType, SongId, PlaylistId?) bool
deleteAllFrom (RoomType) bool
checkIn (RoomType, SongId, PlaylistId?) bool
queryAllIdsFrom (RoomType, PlaylistId?) List<int>

Query methods

Methods Parameters Return
queryFromFavorites (SongId) FavoritesEntity
queryAllFromFavorites (QueryLimit?) List<FavoritesEntity>
queryFromLastPlayed (SongId) LastPlayedEntity
queryAllFromLastPlayed (QueryLimit?) List<LastPlayedEntity>
queryFromMostPlayed (SongId) MostPlayedEntity
queryAllFromMostPlayed (QueryLimit?) List<MostPlayedEntity>
queryFromPlaylist (SongId) PlaylistSongsEntity
queryAllFromPlaylist (QueryLimit?) List<PlaylistSongsEntity>

Playlist methods

Methods Parameters Return
createPlaylist (Entity) int
deletePlaylist (Entity) bool
renamePlaylist (PlaylistId, NewPlaylistName) bool
queryPlaylist (PlaylistId) PlaylistEntity
queryAllPlaylists (QueryLimit?) List<PlaylistEntity>

Examples:

All examples will use on_audio_query plugin to get songs/audios information

addTo

  //If you use [on_audio_query] just extend SongModel to create any entity.
  someName() async {
    //The return will be the song id inside the database.
    int addToResult = await OnAudioRoom().addTo(
      RoomType.FAVORITES, 
      entity[index].toFavoritesEntity,
    );
  }

  //If you don't use [on_audio_query] just create a map with all information.
  someOtherName() async {
    Map<dynamic, dynamic> favoritesEntity = {
      "last_data": song.data,
      "display_name": song.displayName,
      "id": song.id,
      "album": song.album,
      "album_id": song.albumId,
      "artist": song.artist,
      "artist_id": song.artistId,
      "date_added": song.dateAdded,
      "duration": song.duration,
      "title": song.title,
      "artwork": song.artwork,
    };

    //Now, add to the database
    //The return will be the song id inside the database.
    int addToResult = await OnAudioRoom().addTo(
      RoomType.FAVORITES, 
      favoritesEntity,
    ); 
  }

addAllTo

  //If you use [on_audio_query] just extend SongModel to create any entity.
  someName() async {
    //Create a list with all SongModel.
    List<SongModel> listOfSongs;
    List<Map<dynamic, dynamic>> listOfEntities;
    
    //Add all songs from model to entity.
    listOfSongs.forEach(element) {
      listOfEntities.add(element.toFavoritesEntity());
    }

    //Now, add to the database.
    //The return will be a list of song id inside the database.
    List<int> addAllToResult = await OnAudioRoom().addAllTo(
      RoomType.FAVORITES, 
      listOfEntities,
    );
  }

  //If you don't use [on_audio_query] just create a list of map with all information.
  someOtherName() async {
    List<Map<dynamic, dynamic>> listOfEntities;
    listOfSongs.forEach(element) {
      Map<dynamic, dynamic> favoritesEntity = {
      "last_data": song.data,
      "display_name": song.displayName,
      "id": song.id,
      "album": song.album,
      "album_id": song.albumId,
      "artist": song.artist,
      "artist_id": song.artistId,
      "date_added": song.dateAdded,
      "duration": song.duration,
      "title": song.title,
      "artwork": song.artwork,
      };

      listOfEntities.add(favoritesEntity);
    }

    //Now, add to the database
    //The return will be a list of song id inside the database.
    List<int> addAllToResult = await OnAudioRoom().addAllTo(
      RoomType.FAVORITES, 
      favoritesEntity,
    ); 
  }

deleteFrom

  someName() async {
    //The return will be [true] if song has been deleted or [false] if not.
    bool deleteFromResult = await OnAudioRoom().deleteFrom(
      RoomType.FAVORITES,
      SongId,
    );
  }

  //When [Adding/Deleting/Checking] songs from a playlist, remember to add the
  //[PlaylistId] or you'll get a exception.
  someName() async {
    //The return will be [true] if song has been deleted or [false] if not.
    bool deleteFromResult = await OnAudioRoom().deleteFrom(
      RoomType.PLAYLIST_SONGS,
      SongId,
      PlaylistId: PlaylistId,
    );
  }

deleteAllFrom

  //This one it's pretty simple.
  someName() async {
    //The return will be [true] if all songs has been deleted or [false] if not.
    bool deleteAllFromResult = await OnAudioRoom().deleteAllFrom(
      RoomType.FAVORITES,
    );
  }

checkIn

  //You'll use this one to check if some song has already been added.
  //Why? If you try to add the same song twice, will work. To avoid this, check if exist.
  someName() async {
    //The return will be [true] if song has already been added or [false] if not.
    bool checkInResult = await OnAudioRoom().checkIn(
      RoomType.FAVORITES,
      SongId,
    );
  }

queryFromFavorites

  someName() async {
    //With this method you will define a songId and will return all information
    //about this song.
    FavoritesEntity queryFromResult = await OnAudioRoom().queryFromFavorites(
      SongId,
    );
  }

queryFromFavorites

  someName() async {
    //With this method you will get all songs with all information based on Type[Entity].
    //You can add a [int] as parameter to define how much song will return from this query.
    List<FavoritesEntity> queryAllFromResult = await OnAudioRoom().queryAllFromFavorites(
      100, //Default: 50
    );
  }

LICENSE: