I'm developing an Android application with Ionic and Capacitor, and I want to debug my code in Android Studio, but I can't see my "console.log" in logcat.
Thank you for your help.
Here's my code:
async loadFoldersWithMp3() {
try {
const folders = await this.musicScannerService.scanFoldersWithMp3();
console.log(folders);
this.foldersWithMp3 = Array.from(folders); // Convertir l'ensemble en tableau
} catch (error) {
console.error("Erreur lors du chargement des dossiers", error);
}
}
Thank you very much! I think I might have a problem in my code. When I run my app, the Logcat shows a list of all folders instead of just the folders containing .mp3 files, as intended.
my code:
import { Injectable } from '@angular/core';
import { Directory, Filesystem } from '@capacitor/filesystem';
@Injectable({
providedIn: 'root'
})
export class MusicScannerService {
constructor() { }
public async scanFoldersWithMp3(directory: string = ''): Promise<string[]> {
let foldersWithMp3: string[] = [];
await this.scanDirectory(directory, foldersWithMp3);
return foldersWithMp3.filter((value, index, self) => self.indexOf(value) === index); // Filtrer les doublons
}
private async scanDirectory(path: string, foldersWithMp3: string[]): Promise<void> {
try {
const result = await Filesystem.readdir({
directory: Directory.ExternalStorage,
path: path
});
for (const fileName of result.files) {
const fullPath = path ? `${path}/${fileName}` : fileName;
const stat = await Filesystem.stat({
directory: Directory.ExternalStorage,
path: typeof fullPath === 'string' ? fullPath : fullPath.name
});
if (stat.type === 'directory') {
} else if (typeof fullPath === 'string' && fullPath.endsWith('.mp3')) {
console.log("Pas Ok");
} else {
const fileName = (typeof fullPath === 'string') ? fullPath : fullPath.name;
if (fileName.endsWith('.mp3')) {
if (!foldersWithMp3.includes(path)) {
foldersWithMp3.push(path);
}
}
}
}
} catch (error) {
console.error(`Erreur lors du scan du dossier ${path}:`, error);
}
}
}
