private void PlayTrack()
{
if (this.fmodSystem == null)
return;
var sound = this.currentTrkSound;
if (!sound.HasValue)
// No sound loaded
return;
try
{
var chn = this.currentTrkChannel;
if (chn.HasValue)
{
// Make sure we reset this first so we can ignore the callback
this.currentTrkChannel = null;
chn?.Stop();
}
}
catch (FmodInvalidHandleException)
{
// Ignore
}
var channel = this.fmodSystem.PlaySound(sound.Value, this.trkGroup, true);
string trackName = this.currentTrack;
channel.SetCallback((type, data1, data2) =>
{
if (type == ChannelControlCallbackType.End)
{
this.log.Debug("Track {0} ended", trackName);
SendMessage(new AudioFinished
{
Id = trackName,
Type = AudioTypes.Track
});
}
});
this.currentTrkChannel = channel;
// Play
channel.Pause = false;
// Send status message
SendMessage(new AudioStarted
{
Id = trackName,
Type = AudioTypes.Track
});
}