How do I save and load audio on runtime?

0 favourites
  • 4 posts
From the Asset Store
Template for a generic save / load system, fully documented in comments and video
  • I want the user to be able to select an audio file (ogg) from his local drive. Then saving the game and replay the audio file the next time the user opens the game.

    When opening a file with FileChooser it returns a URL to the file. I can use this URL to play the audio (audio Add remote URL).

    I can save this URL, but next time I open the game the audio file at the URL doesn't exist anymore.

    So I already figured out I don't have to save the URL but the audio-file itself.

    I tried with LocalStorage, tried to convert it to BinaryData, ... but can't fetch the data of the audio file.

    My project: drive.google.com/file/d/1eFghbP7HwMKFULSJ_78zX5QiwOzqmp5u/view

    Thanks!

    Wim

  • Maybe I can just always reload the file from the local drive, but then I need the path to the file. Is there a way to get the path to the file from FileChooser? I can get the name of the file, but not the path.

    Wim

  • You can sue AJAX to fetch a URL and store the result in Binary Data. One example that does this is Voice Recorder.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oké, thanks! Now I can put the sound into Binary Data and save the Binary Data to LocalStorage.

    What I can't get working:

    1. loading the data from LocalStorage into BinaryData,

    -> LocalStorage: Get item "audiofile" into BinaryData

    The length of BinaryData stays zero after:

    + LocalStorage: On item "audiofile" get

    -> Text: Append "equal?: " & BinaryData.ByteLength

    2. How can I put this BinaryData somewhere I can access by a URL, because a URL is what the audio-object needs "add remote URL". Or is there another way to put the BinaryData into the Audio-object?

    Many thanks in advance (and sorry for my unclear English)

    Wim

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