using NAudio.Wave;
using FSI.Lib.Guis.WebRadio.Player;
using System;

namespace FSI.Lib.Guis.WebRadio.Helpers
{
    public static class PlayabilityChecker
    {
        public static bool IsPlayable(this IInterface s)
        {
            try
            {
                using (var wo = new WaveOutEvent())
                using (var mf = new MediaFoundationReader(s.Url))
                {
                    float woVol = wo.Volume;
                    wo.Init(mf);
                    wo.Volume = 0;
                    wo.Play();
                    wo.Stop();
                    wo.Volume = woVol;
                    return true;
                }
            }
            catch (Exception)
            {

                return false;
            }
        }
    }
}
