Integration Naudio in Unity: Open your Unity project and create a new C# script.
1 Open your C# script In Visual Studio
2 In Visual Studio, go to "Tools" > "NuGet Package Manager" > "Manage NuGet Packages for Solution".
3 In the "Browse" tab, search for "NAudio" and install the package. (install version 1.8.0 becouse new versions cant work in Unity)
4 Once the package is installed, you can use the NAudio library in your script by adding the following using statement at the top of your script:
using NAudio.Wave;
Thats general link to Github https://github.com/naudio/NAudio/releases
5 U need download NAudio-1.8.0-Release.zip https://github.com/naudio/NAudio/releases/download/NAudio_1.8_Release/NAudio-1.8.0-Release.zip
6 In your Unity project, create a new "Plugins" folder in the "Assets" directory if one does not already exist.
7 Copy the NAudio.dll file and other from NAudio-1.8.0-Release.zip into the "Plugins" folder.
Now u can Use NAudio
This example of code(if you use this example code dont forget change your path to file and check Name of Script :)):
using UnityEngine;
using NAudio.Wave;
public class AudioPlayer : MonoBehaviour
{
private IWavePlayer wavePlayer;
private WaveStream waveStream;
private string audioFilePath = "D:/Walker Hayes - AA (Official Video).mp3";
void Start()
{
// Create WaveStream obj for stream
waveStream = new Mp3FileReader(audioFilePath);
// Create WaveOut obj for play stream
wavePlayer = new WaveOut();
wavePlayer.Init(waveStream);
wavePlayer.Play();
}
void OnApplicationQuit()
{
//stop play
if (wavePlayer != null)
{
wavePlayer.Stop();
wavePlayer.Dispose();
}
if (waveStream != null)
{
waveStream.Dispose();
}
}
}
Implement NAudio in unity game
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment