-
Notifications
You must be signed in to change notification settings - Fork 14
Full Sample
Ross Gouldthorpe edited this page Apr 7, 2017
·
4 revisions
Documentation Go A full sample of setup, load, play, exit A full sample
This sample will show the full set of steps to setting up a driver, trying to load a mod, checking for load errors then playing the mod if correct. Then finish off with unloading the mod once its finished playing.
Using the MikMod Wrapper Class
public static void Main()
{
MikMod player;
player = new MikMod();
player.Init<WavDriver>("cannon.wav");
Module mod = null;
mod = player.LoadModule("cannon.mod");
if(mod != null)
{
player.Play(mod);
// Depending on the driver you might need to call update
// if update is not need calling update will not break anything
// Please note that some mods can loop indefiniatly so might never end.
while(player.IsPlaying())
{
player.Update();
}
player.Stop();
// Calling unload will clear out any loaded samples and the mod data.
// Its fine to then load another module after unloading one.
player.UnLoadModule(mod);
}
else
{
// Failed to load the mod
if(player.HasError)
{
Console.Writeline("Failed to load mod for reason: "+player.Error);
}
}
player.Exit();
}
Using the SharpMik static functions directly
public static void Main()
{
ModDriver.LoadDriver<WavDriver>();
ModDriver.MikMod_Init("cannon.wav");
Module mod = null;
try
{
mod = ModuleLoader.Load("cannon.mod");
}
catch (System.Exception ex)
{
Console.WriteLine("Failed to load mod for reason: "+ex.Message);
}
if(mod != null)
{
ModPlayer.Player_Start(mod);
while (ModPlayer.Player_Active())
{
ModDriver.MikMod_Update();
}
ModPlayer.Player_Stop();
ModuleLoader.UnLoad(mod);
}
ModDriver.MikMod_Exit();
}