Created
April 8, 2019 10:50
-
-
Save apptects/e3a2f42fc020c2b1bc13945cdc75362c to your computer and use it in GitHub Desktop.
Audio clip downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AudioDownloader { | |
| static final AudioDownloader _singleton = new AudioDownloader._internal(); | |
| factory AudioDownloader() { | |
| return _singleton; | |
| } | |
| AudioDownloader._internal(); | |
| Future<String> downloadUrl(String url) async { | |
| Uint8List rawData; | |
| try { | |
| rawData = await readBytes(url); | |
| } on Exception catch(e) { | |
| print('Failed to download $url ($e)'); | |
| return ''; | |
| } | |
| final documentsDirectory = await getApplicationDocumentsDirectory(); | |
| final temporaryFile = File('${documentsDirectory.path}/${basename(url)}'); | |
| await temporaryFile.writeAsBytes(rawData); | |
| return temporaryFile.path; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment