赞
踩
- public static class NAudioPlayer
- {
- public static AudioClip FromMp3Data(byte[] data)
- {
-
- MemoryStream mp3stream = new MemoryStream(data);
-
- Mp3FileReader mp3audio = new Mp3FileReader(mp3stream);
- WaveStream waveStream = WaveFormatConversionStream.CreatePcmStream(mp3audio);
-
- WAV wav = new WAV(AudioMemStream(waveStream).ToArray());
-
- AudioClip audioClip;
- if (wav.ChannelCount == 2) {
- audioClip = AudioClip.Create("Audio File Name", wav.SampleCount, 2, wav.Frequency, false);
- audioClip.SetData(wav.StereoChannel, 0);
- } else {
- audioClip = AudioClip.Create("Audio File Name", wav.SampleCount, 1, wav.Frequency, false);
- audioClip.SetData(wav.LeftChannel, 0);
- }
-
- return audioClip;
- }
-
- private static MemoryStream AudioMemStream(WaveStream waveStream)
- {
- MemoryStream outputStream
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。