How to convert an MP3 file to String ?

  1. 2 weeks ago

    Emile S

    Aug 6 Europe (France, Strasbourg)

    I wrote the code to select and load an mp3 file, but I failed to store it as a String.

    I need the mp3 file (very short, less than 5 seconds) as String to pass to an API who want String as parameter.

    Ideas ?

  2. Norman P

    Aug 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog

    open it as a binary stream and read the entire thing in

  3. Sascha S

    Aug 6 Pre-Release Testers, Xojo Pro Germany, Lower Saxonary
    Edited 2 weeks ago

    Store it in a MemoryBlock and send the StringValue to the API.

    Damn: Norman was faster :)

  4. Emile S

    Aug 6 Europe (France, Strasbourg)

    Thank you guys, worsk fine.

    Now I have in my Clipboard:
    {{«class RTF », 3174}, {«class MPG3», 34056}}

    An RTF text and a MP3 file… ;)

    Picture and Text were lost in the process, more work to do. :(

  5. Alexander v

    Aug 6 Europe (Houten, The Netherland...

    If you read the whole file into a string there should be no loss... the string contains exactly the contents of the file, without any parsing/recognition, of course.

    Public Function FileToString(f as FolderItem) as String
    
      'reads a file as BinaryStream
      'and saves as string to be used in string field type
      'no need for Blobs and fast
      
      dim b as BinaryStream
      dim data as String
      
      
      b = BinaryStream.Open(f,false)
      data = b.Read(b.length)
      if b.ReadError then
        ShowMessage("Error reading file")
        return ""
      end if
      b.close
      Return data 
      
      
    End Function
  6. Emile S

    Aug 6 Europe (France, Strasbourg)

    Thank you Alexander for the code.

    Mine was very basic, but looks similar (I do not needed the error checking, just basic stuff.

    As I wrote earlier, this is a very small mp3 test file… (37 KB).

  7. Sascha S

    Aug 6 Pre-Release Testers, Xojo Pro Germany, Lower Saxonary

    @Emile S I do not needed the error checking

    Outch! ;)

  8. Emile S

    Aug 6 Europe (France, Strasbourg)

    FOR TESTINGS…

    not for production ;)

    Sorry for the fear ;)

or Sign Up to reply!