https://github.com/lucjosin/on_audio_room
Flutter Package used to create a room to storage audio sections [Favorites, Internal Playlists, Most Played, etc...].
https://github.com/lucjosin/on_audio_room
audio-store dart flutter flutter-audio flutter-null-safety flutter-package hive-flutter on-audio-room room
Last synced: 8 months ago
JSON representation
Flutter Package used to create a room to storage audio sections [Favorites, Internal Playlists, Most Played, etc...].
- Host: GitHub
- URL: https://github.com/lucjosin/on_audio_room
- Owner: LucJosin
- License: bsd-3-clause
- Created: 2021-07-26T15:10:29.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-21T16:41:18.000Z (over 4 years ago)
- Last Synced: 2025-05-08T23:42:35.973Z (about 1 year ago)
- Topics: audio-store, dart, flutter, flutter-audio, flutter-null-safety, flutter-package, hive-flutter, on-audio-room, room
- Language: Dart
- Homepage: https://pub.dev/packages/on_audio_room
- Size: 241 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# on_audio_room
[](https://pub.dev/packages/on_audio_room)
[](https://www.android.com/)
[](https://www.flutter.dev/)
`on_audio_room` is a [Flutter](https://flutter.dev/) Package used to create a "room" to storage audio sections [Favorites, Internal Playlists, Most Played, etc...].
This Package works as a "extension" to [on_audio_query](https://github.com/LucJosin/on_audio_query) and some methods will require it.
## Help:
**Any problem? [Issues](https://github.com/LucJosin/on_audio_room/issues)**
**Any suggestion? [Pull request](https://github.com/LucJosin/on_audio_room/pulls)**
### Translations:
NOTE: Feel free to help with readme translations
* [English](README.md)
* [Portuguese](README.pt-BR.md)
### Topics:
* [How to Install](#how-to-install)
* [How to use](#how-to-use)
* [Examples](#examples)
* [License](#license)
## How to Install:
Add the following code to your `pubspec.yaml`:
```yaml
dependencies:
on_audio_room: ^2.2.1+1
```
## Some Features:
* Favorites section
* Last Played section
* Most Played section
* Internal playlists section
## TODO:
* Add better performance for all plugin.
* Add `[Features]`.
* Fix bugs.
## How to use:
Before calling any method you need `init` the room/room's:
```dart
void main() async {
//Init only one room.
await OnAudioRoom().initRoom(RoomType.FAVORITES); //Add the RoomType.
runApp(MaterialApp(home: MyApp()));
}
//Or
void main() async {
//Init all the room's.
await OnAudioRoom().initRoom(); //Don't add the RoomType.
runApp(MaterialApp(home: MyApp()));
}
```
**Important:**
* **This method will ONLY work 100% if you add a async/await, if don't, the widget will load almost in the same time and will throw a error.**
* **REMEMBER TO CLOSE THE ROOM'S INSIDE THE DISPOSE.**
* **See the [documentation](https://pub.dev/documentation/on_audio_room/latest/on_audio_room/OnAudioRoom/initRoom.html)**
```dart
OnAudioRoom() // The main method to start using the plugin.
```
All types of methods on this plugin:
### Room methods
| Methods | Parameters | Return |
|--------------|-----------------|-----------------|
| [`initRoom`]() | `(RoomType, SubDir?)` | `bool` |
| [`closeRoom`]() | | `bool` |
| [`deleteRoomFile`]() | | `bool` |
| [`getRoomInfo`]() | | `RoomEntity` |
| [`clearAll`]() | | `bool` |
### Global methods
| Methods | Parameters | Return |
|--------------|-----------------|-----------------|
| [`addTo`]() | `(RoomType, Entity, PlaylistKey?)` | `int?` |
| [`addAllTo`]() | `(RoomType, Entity, PlaylistKey?)` | `List` |
| [`updateRoom`]() | `(RoomType, Entity)` | `bool` |
| [`deleteFrom`]() | `(RoomType, EntityKey, PlaylistKey?)` | `bool` |
| [`deleteAllFrom`]() | `(RoomType, EntityKeys, PlaylistKey?)` | `bool` |
| [`clearRoom`]() | `(RoomType)` | `bool` |
| [`checkIn`]() | `(RoomType, EntityKey, PlaylistKey?)` | `bool` |
### Query methods
| Methods | Parameters | Return |
|--------------|-----------------|-----------------|
| [`queryFromFavorites`]() | `(EntityKey)` | `FavoritesEntity` |
| [`queryFavorites`]() | `(Limit?, Reverse?, RoomSortType?)` | `List` |
| [`queryFromLastPlayed`]() | `(EntityKey)` | `LastPlayedEntity` |
| [`queryLastPlayed`]() | `(Limit?, Reverse?, RoomSortType?)` | `List` |
| [`queryFromMostPlayed`]() | `(EntityKey)` | `MostPlayedEntity` |
| [`queryMostPlayed`]() | `(Limit?, Reverse?, RoomSortType?)` | `List` |
| [`queryFromPlaylist`]() | `(PlaylistKey, EntityKey)` | `SongEntity` |
| [`queryAllFromPlaylist`]() | `(PlaylistKey, Limit?, Reverse?, RoomSortType?)` | `List` |
### Playlist methods
| Methods | Parameters | Return |
|--------------|-----------------|-----------------|
| [`createPlaylist`]() | `(PlaylistName)` | `int?` |
| [`deletePlaylist`]() | `(PlaylistKey)` | `bool` |
| [`renamePlaylist`]() | `(PlaylistKey, NewName)` | `bool` |
| [`clearPlaylists`]() | | `bool` |
| [`queryPlaylist`]() | `(PlaylistKey)` | `PlaylistEntity` |
| [`queryPlaylists`]() | `(Limit?, Reverse?)` | `List` |
## Examples:
**All examples will use [on_audio_query] plugin to get songs/audios information**
#### addTo
```dart
//If you use [on_audio_query] just extend SongModel to create any entity.
someName() async {
//The return will be the song id inside the room.
int? addToResult = await OnAudioRoom().addTo(
RoomType.FAVORITES,
entity[index].getMap.toFavoritesEntity(),
);
}
//If you don't use [on_audio_query] just create a map with all information.
someOtherName() async {
Map favoritesEntity = {
"_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 room
//The return will be the song key inside the room.
int? addToResult = await OnAudioRoom().addTo(
RoomType.FAVORITES,
favoritesEntity.toFavoritesEntity(),
);
}
```
#### addAllTo
```dart
//If you use [on_audio_query] just extend SongModel to create any entity.
someName() async {
//Create a list with all SongModel.
List listOfSongs;
List listOfEntities;
//Add all songs from model to entity.
listOfSongs.forEach(element) {
listOfEntities.add(element.getMap.toFavoritesEntity());
}
//Now, add to the room.
//The return will be a list of song id inside the room.
List addAllToResult = await OnAudioRoom().addAllTo(
RoomType.FAVORITES,
listOfEntities,
//playlistKey,
);
}
//If you don't use [on_audio_query] just create a list of map with all information.
someOtherName() async {
List listOfEntities;
listOfSongs.forEach(element) {
Map 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.toFavoritesEntity());
}
//Now, add to the room
//The return will be a list of song id inside the room.
List addAllToResult = await OnAudioRoom().addAllTo(
RoomType.FAVORITES,
favoritesEntity,
//playlistKey,
);
}
```
#### deleteFrom
```dart
someName() async {
//The return will be [true] if song has been deleted or [false] if not.
bool deleteFromResult = await OnAudioRoom().deleteFrom(
RoomType.FAVORITES,
EntityKey,
//playlistKey,
);
}
//When [Adding/Deleting/Checking] songs from a playlist, remember to add the
//[PlaylistKey] 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,
EntityKey,
PlaylistKey: PlaylistKey,
);
}
```
#### deleteAllFrom
```dart
someName() async {
List listOfKeysToDelete = [...];
//The return will be [true] if all songs has been deleted or [false] if not.
bool deleteAllFromResult = await OnAudioRoom().deleteAllFrom(
RoomType.FAVORITES,
listOfKeysToDelete,
//playlistKey,
);
}
```
#### clearRoom
```dart
//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().clearRoom(
RoomType.FAVORITES,
//playlistKey,
);
}
```
#### checkIn
```dart
//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,
EntityKey,
//playlistKey,
);
}
```
#### queryFromFavorites
```dart
someName() async {
//With this method you will define a key and will return all information
//about this favorite song.
FavoritesEntity? queryFromResult = await OnAudioRoom().queryFromFavorites(
EntityKey,
);
}
```
#### queryFavorites
```dart
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.
//You can add a [bool] as parameter to define if list will be reversed or no.
//You can add a [RoomSortType] as parameter to define the list sort type.
List queryResult = await OnAudioRoom().queryFavorites(
100, //Default: 50
true, //Default: false
RoomSortType.TITLE //Default: null
);
}
```
## LICENSE:
* [LICENSE](https://github.com/LucJosin/on_audio_room/blob/main/LICENSE)
> * [Back to top](#on_audio_room)