How to play google drive's mp3 file in Flutter

311

you have to try direct url for your file like this

https://drive.google.com/uc?export=download&confirm=no_antivirus&id=1v8RBvEOpsEDlD_o7OA2TKgxysF-O5jUW
Share:
311
santosh mahat
Author by

santosh mahat

Updated on December 24, 2022

Comments

  • santosh mahat
    santosh mahat over 1 year

    I have uploaded some mp3 files to my google drive. And now I want to play those mp3 files in my flutter app using audioplayers package. https://drive.google.com/file/d/1v8RBvEOpsEDlD_o7OA2TKgxysF-O5jUW/view?usp=sharing. This is my public shareable link of my mp3 on google drive.

      void getAudio() async {
       var url =
          "https://drive.google.com/file/d/1v8RBvEOpsEDlD_o7OA2TKgxysF-O5jUW/view?usp=sharing";
       if (isPlaying) {
         var res = await audioPlayer.pause();
         if (res == 1) {
           print("isPlaying $res");
           setState(() {
             isPlaying = false;
           });
         }
       } else {
         var res = await audioPlayer.play(url, isLocal: false);
         print("!isPlaying $res");
         if (res == 1) {
           setState(() {
             isPlaying = true;
           });
         }
       }
       audioPlayer.onDurationChanged.listen((Duration d) {
         setState(() {
           duration = d;
         });
       });
       audioPlayer.onAudioPositionChanged.listen((Duration d) {
         setState(() {
           position = d;
         });
       });
     }
    
    • Hamza
      Hamza over 3 years
      Hey, did you find out a way yet?