1

I want to fetch mp3 files from phone storage with specific folder,

Actually am using on_audio_query pkg for this but on_audio_query is fetched all mp3 files in my phone storage.

please anyone guide!

code:

@override
    final _onAudioQuery = OnAudioQuery();
  final AudioPlayer audioPlayer = AudioPlayer();

void initState() {
requestPermission();

myPath();
super.initState();

  }

     void requestPermission() {
    Permission.storage.request();
  }



    String? appDocPath;
  Future<void> myPath() async {
    Directory? appDocDir = await getExternalStorageDirectory();
    setState(() {
      appDocPath = appDocDir!.path.toString();
      print("dir lenght: ${appDocPath}".length.toString());
    });
  }


    @override
  Widget build(BuildContext context) {
    print("dir: ${appDocPath}".toString());
    return Scaffold(
      appBar: AppBar(),
      body: FutureBuilder<List<SongModel>>(
        future: _onAudioQuery.querySongs(
          path: appDocPath,
          sortType: null,
          orderType: OrderType.ASC_OR_SMALLER,
          uriType: UriType.EXTERNAL,
          ignoreCase: true,
        ),

............

1 Answers1

0
someName() async {
    OnAudioQuery _audioQuery = OnAudioQuery();
    File file = File('path');
    try {
      if (file.existsSync()) {
 
        _audioQuery.scanMedia(file.path); // Scan the media 'path'
      }
    } catch (e) {
      debugPrint('$e');
    }
  }

change path to your device path.

MohitJadav86
  • 782
  • 3
  • 11