public bool TogglePlay ()
{
stateChangeQueue.DispatchSync (() => {
if (isPlaying) {
player.Stop ();
engine.Stop ();
isPlaying = false;
SetSessionActive (false);
} else {
SetSessionActive (true);
ScheduleLoop ();
ScheduleLoop ();
NSError error;
if(!engine.StartAndReturnError (out error))
Console.WriteLine (error.LocalizedDescription);
player.Play ();
isPlaying = true;
}
});
return isPlaying;
}