- Home /
How to convert File Resource .ogg using IO.Stream into AudioClip with a C# Script?
I already have a File Resource in my assembly with the name of the music "ReanimationOST.ogg", I tried to convert it using GetManifestResourceStream to turn it into an AudioClip with 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 being is that the channels and frequency is being 0, making the assembly stop because both needs to be greated value than 0.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613055228im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I properly stream music with WWWAudioExtensions? 1 Answer
File.Create not working 0 Answers