//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if WIN32
using System;
using System.Media;
using System.IO;
using System.Runtime.CompilerServices;

namespace CommonHelpers {

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class HSoundPlayer {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static void PlayStream([HOptional] Stream stream)
{
   PlayStream(stream,false);
}

public static void PlayStream([HOptional] Stream stream,bool ignoreMute)
{
   PlayStream(stream,ignoreMute,false);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void PlayStream([HOptional] Stream stream,bool ignoreMute,bool synchronously)
{
   if (stream!=null && (ignoreMute || !HSound.IsMute))
   {
      var soundPlayer = new SoundPlayer();
      soundPlayer.Stream = stream;
      if (synchronously)
         soundPlayer.PlaySync();
      else
         soundPlayer.Play();
   }
}

//==================================================================================================

public static bool PlayFile([HOptional] string entryModuleRelativeLocation)
{
   return PlayFile(entryModuleRelativeLocation,false);
}

public static bool PlayFile([HOptional] string entryModuleRelativeLocation,bool ignoreMute)
{
   return PlayFile(entryModuleRelativeLocation,ignoreMute,false);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool PlayFile( [HOptional] string entryModuleRelativeLocation,
                             bool ignoreMute, bool synchronously )
{
   if (entryModuleRelativeLocation!=null && (ignoreMute || !HSound.IsMute))
   {
      string
         filePath = Path.Combine( HProgram.EntryModuleDirectory,
                                  entryModuleRelativeLocation );
      if (!File.Exists( filePath ))
         return false;
      var soundPlayer =
         new SoundPlayer( filePath );
      if (synchronously)
         soundPlayer.PlaySync();
      else
         soundPlayer.Play();
   }
   return true;
}

//==================================================================================================

public static void SyncPlayStream([HOptional] Stream stream)
{
   SyncPlayStream(stream,false);
}

public static void SyncPlayStream([HOptional] Stream stream,bool ignoreMute)
{
   PlayStream(stream,ignoreMute,true);
}

//--------------------------------------------------------------------------------------------------

public static bool SyncPlayFile([HOptional] string entryModuleRelativeLocation)
{
   return SyncPlayFile(entryModuleRelativeLocation,false);
}

public static bool SyncPlayFile([HOptional] string entryModuleRelativeLocation,bool ignoreMute)
{
   return PlayFile(entryModuleRelativeLocation,ignoreMute,true);
}

//==================================================================================================

static HSoundPlayer()
{
   CommonHelpers_Plus.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HSoundPlayer
//**************************************************************************************************

} // CommonHelpers
#endif // WIN32
