Tau: [Feature] Playback from asset

Created on 21 Dec 2018  路  3Comments  路  Source: Canardoux/tau

Version of flutter_sound

1.2.1

At the moment, startPlayer requires a URI, which the assets don't have. I think I can hack a workaround to this via path_provider, but it would be useful to be able to playback directly from assets as well.

Thanks for the library!

Most helpful comment

For anyone else needing a temp fix to this, https://github.com/palfrey/spaceteam-timer/blob/8d1c2e0a4cd4bb991b42a0ca02859263d24d1984/lib/setup.dart has setupMusicFiles which makes sure all my assets are dumped to the filesystem, and pathForLength that will get the path to the file. flutterSound.startPlayer('file://$path') then works fine.

All 3 comments

For anyone else needing a temp fix to this, https://github.com/palfrey/spaceteam-timer/blob/8d1c2e0a4cd4bb991b42a0ca02859263d24d1984/lib/setup.dart has setupMusicFiles which makes sure all my assets are dumped to the filesystem, and pathForLength that will get the path to the file. flutterSound.startPlayer('file://$path') then works fine.

Thanks @palfrey

Here's what I used, based on your suggestion:

  Future<String> setupMusicFile() async {
    final dir = await getApplicationDocumentsDirectory();
    final file = File('${dir.path}/pad.mp3');
    if (!await file.exists()) {
      var data = await rootBundle.load('resources/sounds/pad.mp3');
      await file.writeAsBytes(data.buffer.asInt8List());
    }
    return file.path;
  }

and then something like this...

    setupMusicFile().then((path) {
      if (!flutterSound.isPlaying) {
        flutterSound.startPlayer(path);
      }
    });

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

satyajitghana picture satyajitghana  路  3Comments

mhstoller picture mhstoller  路  5Comments

gtilson picture gtilson  路  5Comments

ggirotto picture ggirotto  路  3Comments

hanj315 picture hanj315  路  5Comments