Skip to content

Commit

Permalink
Update 2.1.1 - Fixed #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Pinheiro committed Aug 24, 2021
1 parent 07f0cff commit 3a321e8
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 42 deletions.
12 changes: 11 additions & 1 deletion on_audio_query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [2.1.1] - [08.23.2021]
### Fixes
#### Android
- Fixed error when using `[removeFromPlaylist]`. - [Fixed #22](https://github.com/LucasPJS/on_audio_query/issues/22)

### Documentation
- Updated `README` documentation.
- Updated `[OnAudioQueryExample]` to support `[Web]` platform.

## [2.1.0] - [08.23.2021]
### Features
#### on_audio_query
Expand Down Expand Up @@ -42,7 +51,7 @@ See all development [changes](https://github.com/LucasPJS/on_audio_query/blob/ma

### Fixes
#### Android
- Fixed no value returning when using `[requestPermission]`.
- Fixed no value returning when using `[permissionsRequest]`.

### Documentation
- Updated `README` documentation.
Expand Down Expand Up @@ -531,6 +540,7 @@ See all development [changes](https://github.com/LucasPJS/on_audio_query/blob/ma
-->

<!--
https://github.com/LucasPJS/on_audio_query/issues/
- [Added #Issue](Link)
- [Fixed #Issue](Link)
- [Changed #Issue](Link)
Expand Down
30 changes: 22 additions & 8 deletions on_audio_query/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# on_audio_query
[![Pub.dev](https://img.shields.io/pub/v/on_audio_query?color=9cf&label=Pub.dev&style=flat-square)](https://pub.dev/packages/on_audio_query)
[![Platforms](https://img.shields.io/badge/Platforms-Android%20%7C%20IOS-9cf?&style=flat-square)]()
[![Languages](https://img.shields.io/badge/Languages-Flutter%20%7C%20Kotlin%20%7C%20Swift-9cf?&style=flat-square)]()
[![Platforms](https://img.shields.io/badge/Platforms-Android%20%7C%20IOS%20%7C%20Web-9cf?&style=flat-square)]()
[![Languages](https://img.shields.io/badge/Languages-Dart%20%7C%20Kotlin%20%7C%20Swift-9cf?&style=flat-square)]()

`on_audio_query` is a [Flutter](https://flutter.dev/) Plugin used to query audios/songs 🎶 infos [title, artist, album, etc..] from device storage. <br>

Expand Down Expand Up @@ -63,13 +63,13 @@ NOTE: Feel free to help with readme translations
✔️ -> Supported <br>
❌ -> Not Supported <br>

**[See all platforms methods support](https://github.com/LucasPJS/on_audio_query/blob/main/PLATFORMS.md)**
**[See all platforms methods support](https://github.com/LucasPJS/on_audio_query/blob/main/on_audio_query/PLATFORMS.md)**

## How to Install:
Add the following code to your `pubspec.yaml`:
```yaml
dependencies:
on_audio_query: ^2.1.0
on_audio_query: ^2.1.1
```
### Request Permission:
Expand All @@ -91,6 +91,20 @@ To use this plugin add the following code to your `Info.plist`
<string>..Add a reason..</string>
```
#### Web:
Since Web Browsers **don't** offer direct access to their user's `file system`, this plugin will use the `assets` folder to "query" the audios files. So, will totally depend of the `developer`.
```yaml
# You don't need add every audio file path, just define the folder.
assets:
- assets/
# If your files are in another folder inside the `assets`:
- assets/audios/
# - assets/audios/animals/
# - assets/audios/animals/cat/
# ...
```

## Some Features:

* Optional and Built-in storage `READ` and `WRITE` permission request
Expand All @@ -107,7 +121,7 @@ To use this plugin add the following code to your `Info.plist`
## TODO:

* Add better performance for all plugin.
* Add support to Web/Windows/MacOs/Linux.
* Add support to Windows/MacOs/Linux.
* Option to remove songs.
* Fix bugs.

Expand Down Expand Up @@ -137,8 +151,8 @@ All types of methods on this plugin:
|--------------|-----------------|-----------------|
| [`createPlaylist`]() | `(PlaylistName, RequestPermission)` | `bool` | <br>
| [`removePlaylist`]() | `(PlaylistId, RequestPermission)` | `bool` | <br>
| [`addToPlaylist`]() | **[NT-BG]**`(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`removeFromPlaylist`]() | **[NT]**`(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`addToPlaylist`]() | **[BG]**`(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`removeFromPlaylist`]() | `(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`renamePlaylist`]() | `(PlaylistId, NewName, RequestPermission)` | `bool` | <br>
| [`moveItemTo`]() | **[NT]**`(PlaylistId, From, To, RequestPermission)` | `bool` | <br>

Expand Down Expand Up @@ -259,6 +273,6 @@ Or you can use a basic and custom Widget.

## LICENSE:

* [LICENSE](https://github.com/LucasPJS/on_audio_query/blob/main/LICENSE)
* [LICENSE](https://github.com/LucasPJS/on_audio_query/blob/main/on_audio_query/LICENSE)

> * [Back to top](#on_audio_query)
30 changes: 22 additions & 8 deletions on_audio_query/README.pt-BR.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# on_audio_query
[![Pub.dev](https://img.shields.io/pub/v/on_audio_query?color=9cf&label=Pub.dev&style=flat-square)](https://pub.dev/packages/on_audio_query)
[![Platforms](https://img.shields.io/badge/Platform-Android%20%7C%20IOS-9cf?&style=flat-square)]()
[![Languages](https://img.shields.io/badge/Language-Flutter%20%7C%20Kotlin%20%7C%20Swift-9cf?&style=flat-square)]()
[![Platforms](https://img.shields.io/badge/Platform-Android%20%7C%20IOS%20%7C%20Web-9cf?&style=flat-square)]()
[![Languages](https://img.shields.io/badge/Language-Dart%20%7C%20Kotlin%20%7C%20Swift-9cf?&style=flat-square)]()

`on_audio_query` é um [Flutter](https://flutter.dev/) Plugin usado para adquirir informações de áudios/músicas 🎶 [título, artista, album, etc..] do celular. <br>

Expand Down Expand Up @@ -63,13 +63,13 @@ NOTE: Fique à vontade para ajudar nas traduções
✔️ -> Tem suporte <br>
❌ -> Não tem suporte <br>

**[Veja todos os suportes](./PLATFORMS.md)**
**[Veja todos os suportes](https://github.com/LucasPJS/on_audio_query/blob/main/on_audio_query/PLATFORMS.md)**

## Como instalar:
Adicione o seguinte codigo para seu `pubspec.yaml`:
```yaml
dependencies:
on_audio_query: ^2.1.0
on_audio_query: ^2.1.1
```
#### Solicitar Permissões:
Expand All @@ -91,6 +91,20 @@ Para usar esse plugin adicione o seguinte código no seu `Info.plist`
<string>..Adicione um motivo..</string>
```

#### Web:
Já que os navegadores **não** oferecem acesso direto ao `file system` dos usuários, esse plugin irá usar a pasta `assets` para "pegar" os audios. Então, dependerá totalmente do `desenvolvedor`.

```yaml
# Você não precisa adicionar todos os audios, apenas defina a pasta.
assets:
- assets/
# Se seus arquivos estão em outra pasta dentro de `assets`:
- assets/audios/
# - assets/audios/animals/
# - assets/audios/animals/cat/
# ...
```

## Algumas qualidades:

* Opcional e Interna solicitação de permissão para `LER` e `ESCREVER`.
Expand All @@ -108,7 +122,7 @@ Para usar esse plugin adicione o seguinte código no seu `Info.plist`
## Para fazer:

* Adicionar uma melhor performace para todo o plugin.
* Adicionar suporte para Web/Windows/MacOs/Linux.
* Adicionar suporte para Windows/MacOs/Linux.
* Opção para remover músicas.
* Arrumar erros.

Expand Down Expand Up @@ -138,8 +152,8 @@ Todos os tipos de métodos nesse plugin:
|--------------|-----------------|-----------------|
| [`createPlaylist`]() | `(PlaylistName, RequestPermission)` | `bool` | <br>
| [`removePlaylist`]() | `(PlaylistId, RequestPermission)` | `bool` | <br>
| [`addToPlaylist`]() | **[NT-BG]**`(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`removeFromPlaylist`]() | **[NT]**`(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`addToPlaylist`]() | **[BG]**`(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`removeFromPlaylist`]() | `(PlaylistId, AudioId, RequestPermission)` | `bool` | <br>
| [`renamePlaylist`]() | `(PlaylistId, NewName, RequestPermission)` | `bool` | <br>
| [`moveItemTo`]() | **[NT]**`(PlaylistId, From, To, RequestPermission)` | `bool` | <br>

Expand Down Expand Up @@ -247,6 +261,6 @@ Ou você pode usar um Widget básico e customizável.

## LICENÇA:

* [LICENSE](https://github.com/LucasPJS/on_audio_query/blob/main/LICENSE)
* [LICENSE](https://github.com/LucasPJS/on_audio_query/blob/main/on_audio_query/LICENSE)

> * [Voltar ao Topo](#on_audio_query)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OnPlaylistsController {

//Query projection
private val columns = arrayOf(
"count(*)"
"count(*)"
)

//
Expand Down Expand Up @@ -50,7 +50,7 @@ class OnPlaylistsController {
}
}

//TODO option for list
//TODO Add option to use a list
//TODO Fix error on Android 10
fun addToPlaylist(context: Context, result: MethodChannel.Result, call: MethodCall) {
this.resolver = context.contentResolver
Expand All @@ -61,8 +61,8 @@ class OnPlaylistsController {
//Check if Playlist exists based in Id
if (!checkPlaylistId(playlistId)) result.success(false)
else {
val uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId.toLong())
Log.i("Uri", uri.toString())
val uri =
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId.toLong())
//If Android is Q/10 or above "count(*)" don't count, so, we use other method.
val columnsBasedOnVersion = if (Build.VERSION.SDK_INT < 29) columns else null
val cursor = resolver.query(uri, columnsBasedOnVersion, null, null, null)
Expand All @@ -77,22 +77,33 @@ class OnPlaylistsController {
contentValues.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId.toLong())
resolver.insert(uri, contentValues)
result.success(true)
} catch (e: Exception) { Log.i(channelError, e.toString()) }
} catch (e: Exception) {
Log.i(channelError, e.toString())
}
}
}

//
//TODO Add option to use a list
fun removeFromPlaylist(context: Context, result: MethodChannel.Result, call: MethodCall) {
this.resolver = context.contentResolver
val playlistId = call.argument<Int>("playlistId")!!
val audioId = call.argument<Int>("audioId")!!

//Check if Playlist exists based in Id
//Check if Playlist exists based on Id
if (!checkPlaylistId(playlistId)) result.success(false)
else {
val uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId.toLong())
resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + " = " + audioId.toLong(), null)
result.success(true)
try {
val uri = MediaStore.Audio.Playlists.Members.getContentUri(
"external",
playlistId.toLong()
)
val where = MediaStore.Audio.Playlists.Members._ID + "=?"
resolver.delete(uri, where, arrayOf(audioId.toString()))
result.success(true)
} catch (e: Exception) {
Log.i("on_audio_error: ", e.toString())
result.success(false)
}
}
}

Expand Down Expand Up @@ -128,8 +139,14 @@ class OnPlaylistsController {
}

//Return true if playlist already exist, false if don't exist
private fun checkPlaylistId(plId: Int) : Boolean {
val cursor = resolver.query(uri, arrayOf(MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists._ID), null, null, null)
private fun checkPlaylistId(plId: Int): Boolean {
val cursor = resolver.query(
uri,
arrayOf(MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists._ID),
null,
null,
null
)
while (cursor != null && cursor.moveToNext()) {
val playListId = cursor.getInt(1) //Id
if (playListId == plId) return true
Expand Down
29 changes: 17 additions & 12 deletions on_audio_query/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Copyright: © 2021, Lucas Josino. All rights reserved.

import 'package:flutter/material.dart';
import 'package:on_audio_query/on_audio_query.dart';
import 'package:flutter/foundation.dart' show kIsWeb;

void main() {
runApp(Songs());
Expand All @@ -27,19 +28,22 @@ class Songs extends StatefulWidget {
class _SongsState extends State<Songs> {
OnAudioQuery audioQuery = OnAudioQuery();

// @override
// void initState() {
// super.initState();
// requestPermission();
// }
@override
void initState() {
super.initState();
requestPermission();
}

// requestPermission() async {
// bool permissionStatus = await audioQuery.permissionsStatus();
// if (!permissionStatus) {
// await audioQuery.permissionsRequest();
// }
// setState(() {});
// }
requestPermission() async {
// Web platform don't have permissions methods.
if (!kIsWeb) {
bool permissionStatus = await audioQuery.permissionsStatus();
if (!permissionStatus) {
await audioQuery.permissionsRequest();
}
setState(() {});
}
}

@override
Widget build(BuildContext context) {
Expand All @@ -56,6 +60,7 @@ class _SongsState extends State<Songs> {
uriType: UriType.EXTERNAL,
),
builder: (context, item) {
// Load content
if (item.data == null) return CircularProgressIndicator();

// When you try "query" without asking for [READ] or [Library] permission
Expand Down
2 changes: 1 addition & 1 deletion on_audio_query/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: on_audio_query
description: Flutter Plugin used to query audios/songs infos [title, artist, album, etc..] from device storage.
version: 2.1.0
version: 2.1.1
homepage: https://github.com/LucasPJS/on_audio_query
# pub.dev: https://pub.dev/packages/on_audio_query
# ========
Expand Down

0 comments on commit 3a321e8

Please sign in to comment.