santosh mahat
santosh mahat

Reputation: 41

How to play google drive's mp3 file in Flutter

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;
     });
   });
 }

Upvotes: 1

Views: 648

Answers (1)

Alexandr Sizykh
Alexandr Sizykh

Reputation: 21

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

Upvotes: 2

Related Questions