- Home /
Play audio from byte array
Hey guys,
I've searched around a bit, but didn't find anything helpful. If I missed something, please let me know! Anyway, I have an encrypted wav file that I want to play using Unity's built-in audio system. The issue is that once I decrypt it, it can't be within reach of the user, so I have to keep it as a byte array. But, I can't find any way to play audio from a byte array, and that's my issue.
So, if you have any suggestions, tips, comments, et cetera, please let me know!
Thanks for taking the time to read this! - Gibson
Answer by GerryM · Feb 16, 2013 at 09:00 PM
You could make an asset bundle with your (decrypted) sound file. Then encrypt the bundle file.
To play, load that file into memory, decrypt it at runtime and use CreateFromMemory to access your asset. Then you could load the audio source and play it. Just an idea.
edit----
Or you could load your custom data, decrypt it, then convert the byte array to a float array. Then you can create an audio clip and fill it with your float data.
-EditEdit- After some critical thinking (something I guess I don't excel at, considering how long it took for me to figure this out), I've realized I can make the audio an asset bundle before I upload it. I feel really stupid, dismissing this option because I couldn't make an asset bundle from my file in memory. Anyway, I think that the asset bundle option is what I'm going with, so thanks for suggesting it to me!
-Edit- Both options won't work, sorry, but thanks for the ideas! The issue with the second is that I need to use compressed WAVs, and I can't seem to get samples from them.
The first option won't work, because it isn't in memory; it's downloaded at runtime, already encrypted. But, the second option might work. What do you mean, "load your custom data"? Also, after the file is decrypted, it's in a byte array, so would I just convert that to a float array, or would I have to get samples from it, or something?
Thanks for the help, I really appreciate it!
oh!Just Give this to JAVA or IOS API can achieve your goal。
I have encountered this problem,THE audio I use to Play is down from server as Byte[]。$$anonymous$$y solution is Give this to JAVA or IOS API。Sometimes, You will find that you must Convert the simple things To asset bundle ......Oh,Fuck the Shit asset bundle