using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;

namespace PlaySound_CS
{
    public partial class Form1 : Form
    {
        // Синхронное воспроизведение
        [DllImport("aygshell.dll")]
        static extern uint SndPlaySync(string pszSoundFile, uint dwFlags);

        // Асинхронное воспроизведение
        [DllImport("aygshell.dll")]
        static extern uint SndOpen(string pszSoundFile, ref IntPtr phSound);

        [DllImport("aygshell.dll")]
        static extern uint SndPlayAsync(IntPtr hSound, uint dwFlags);

        [DllImport("aygshell.dll")]
        static extern uint SndClose(IntPtr hSound);

        [DllImport("aygshell.dll")]
        static extern uint SndStop(int SoundScope, IntPtr hSound);


        public Form1()
        {
            InitializeComponent();
            #if DEBUG
                MinimizeBox = false;
            #else       
                MinimizeBox = true;
            #endif
        }

        private void butResource_Click(object sender, EventArgs e)
        {
            Sound sound = new Sound(Assembly.GetExecutingAssembly().GetManifestResourceStream("PlaySound_CS.chimes.wav"));
            sound.Play();

        }

        private void butFile_Click(object sender, EventArgs e)
        {
            Sound sound = new Sound("Windows\\alarm3.wav");
            sound.Play();

        }

        private void butMP3Play_Click(object sender, EventArgs e)
        {
            string path = @"\Storage Card\dudachi.mp3";
            if (System.IO.File.Exists(path))
            {
                SndPlaySync(path, 0);
            }
        }

        IntPtr hSound = IntPtr.Zero;
        const string path = @"\Storage Card\dudachi.mp3";
        const int SND_SCOPE_PROCESS = 0x1;

        void Play()
        {
            SndOpen(path, ref hSound);
            SndPlayAsync(hSound, 0);
        }

        void Stop()
        {
            SndClose(hSound);
            SndStop(SND_SCOPE_PROCESS, IntPtr.Zero);
        } 


        private void butStart_Click(object sender, EventArgs e)
        {
            Play();
        }

        private void butStop_Click(object sender, EventArgs e)
        {
            Stop();
        }
    }
}