- Home /
How to change a File Resource .ogg using IO.Stream into an AudioClip with a C# Script?,Anyone know how to turn an IO.Stream into an AudioClip through a C# script?
I wanted to change a File Resource in my assembly with the name of the music "ReanimationOST.ogg" into an AudioClip by using IO.Stream, I tried this script:
AudioClip result; using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ReanimationOST.ogg")) { ushort channels = BitConverter.ToUInt16(new byte[manifestResourceStream.Length], 22); int sampleRate = BitConverter.ToInt32(new byte[manifestResourceStream.Length], 24); result = AudioClip.Create("Reanimated", (int)manifestResourceStream.Length, (int)channels, sampleRate, false); }
The problem is the channels and frequencies are always 0 and it always crashes because it required both to be greater than 0.
Anyone please could help me with this one?
Comment