How do I retrieve and play audio recordings saved as binary data to local storage?

1 favourites
  • 5 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • Hi, I'm building an app that allows users to record an audio sample, save the data, then in subsequent sessions retrieve the data and play it back.

    Following the Voice Recorder example, I think I've managed to get the binary data into local storage (I can see it as an item in the Local Storage object in debug), but I don't know how to extract it into a suitable format for playing.

    These are the steps taken to save the data:

    It shows in the local storage as:

    To retrieve the data I've got as far as:

    ...but I'm unsure where to go next. Is saving the files to local storage even the best way to do this or should I be saving them directly as audio files to a directory (as in the Voice Recorder example) and then retrieving them from there? Note that I would like the user to be able to retrieve multiple saved samples for use simultaneously, if that makes any difference to the best method.

    Any help greatly appreciated.

    Tagged:

  • The way you save the recording looks good. If you want to play that data back, one way to do that is to get the data from the BinaryData object in Base64 format using BinaryData.GetBase64. Assign the data in that format to a string local variable (i'll call it Base64String).

    Now you have to use the Add Remote URL action (Audio) to add the recording so that you can play it. Since the URL you pass to the action itself will be applied to the src field of the html audio element, you can pass as URL "data:audio/mp3;base64,"&Base64String and leave the other parameters unchanged (except for the name) to be able to play your sound by name.

    I tried this solution and it works fine, even though there may be more efficient ways to do the same thing. Give it a try :)

  • hello!

    Please give us the source code so that you can download 10 sounds

    I will be grateful!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • BigBuckBunny This worked perfectly, thank you! I would have spent ages trying to work out the binary format and URL structure.

    I've modified the storage to save the binary string as a dictionary value - this allows me to save multiple samples into a single dictionary and then save that to local storage.

  • Good afternoon!

    Can you help me with the same question?

    I need a working source code to figure

    it out I want to download and save some sounds

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)