Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: How to pass a String variable into AudioPlaySerialflashRaw::play() ??

  1. #1

    How to pass a String variable into AudioPlaySerialflashRaw::play() ??

    Hey guys,

    Maybe a silly question but I can't figure out how to assign a filename to a String, say "KICK014.RAW" for example, and then pass that String into AudioPlaySerialflashRaw :: play(const char *filename). Obviously it says it takes a char variable, but I dont understand what to do with that information, since my only experience with chars has been that they hold a single character.

    To be clear this is all I want to do:

    Code:
    String filename = "K014.RAW";
    serialFlashRaw.play(filename);
    But it won't compile, cause there's no matching function for passing in a String like that.
    Thanks for any help!

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,699
    Just say no to string

    Need to pass c string to function,so look at string member c_str()

  3. #3
    Hey thanks for the help! Unfortunately it still isn't working... based on what I've read about c_str() this should be correct, no?

    Code:
    String filename = "K014.RAW";
    serialFlashRaw.play(filename.c_str());

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,077
    Does this work?

    Code:
    serialFlashRaw.play(  "K014.RAW" );

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,077
    Is there a console error in verbose shown? Or does it compile and fail to work?

  6. #6
    Okay problem solved: The code I included in my second post works fine but I was using 85% of dynamic memory and at runtime my string variable was getting scrambled to where it was blank if I tried to print it. I brought AudioMemory(140) down to 100 and now it works like it should. Thanks for the help you two!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •