Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten.zip
BSE.Platten
BSE.Platten.vssscc
mssccprj.scc
vssver2.scc
BSE.CoverFlow.WPFLib
BSE.CoverFlow.WPFLib.csproj.user
BSE.CoverFlow.WPFLib.csproj.vspscc
mssccprj.scc
vssver2.scc
Images
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp
BSE.Platten.Admin.WinApp.csproj.user
BSE.Platten.Admin.WinApp.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
BSEadmin.ico
vssver2.scc
BSE.Platten.Audio
bse.ico
BSE.Platten.Audio.csproj.vspscc
mssccprj.scc
vssver2.scc
Options
vssver2.scc
Player
vssver2.scc
Properties
vssver2.scc
Resources
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
WinControls
vssver2.scc
WMFSDK
vssver2.scc
BSE.Platten.BO
BSE.Platten.BO.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Common
BSE.Platten.Common.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers
BSE.Platten.Covers.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
BSE.Platten.FreeDb
BSE.Platten.FreeDb.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
vssver2.scc
BSE.Platten.Ripper
BSE.Platten.Ripper.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik
BSE.Platten.Statistik.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Tunes
BSE.Platten.Tunes.csproj.user
BSE.Platten.Tunes.csproj.vspscc
mssccprj.scc
vssver2.scc
Filters
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup
BSEadminSetup.vdproj
BSEadminSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
BSEtunesSetup
BSEtunesSetup.vdproj
BSEtunesSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
dll
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.Windows.Forms.DLL
Lame
lame_enc.dll
vssver2.scc
lame-3.97
BSE.Platten_en.zip
BSE.CoverFlow.WPFLib.csproj.user
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Settings.settings
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
Settings.settings
vssver2.scc
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp.csproj.user
Settings.settings
vssver2.scc
BSEadmin.ico
vssver2.scc
bse.ico
BSE.Platten.Audio.csproj.user
vssver2.scc
vssver2.scc
vssver2.scc
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.BO.csproj.user
vssver2.scc
BSE.Platten.Common.csproj.user
vssver2.scc
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers.csproj.user
Settings.settings
vssver2.scc
BSE.Platten.FreeDb.csproj.user
vssver2.scc
OpenCD.png
vssver2.scc
AudioWriter
vssver2.scc
BSE.Platten.Ripper.csproj.user
Lame
vssver2.scc
vssver2.scc
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik.csproj.user
vssver2.scc
BSE.Platten.Tunes.csproj.user
vssver2.scc
Settings.settings
vssver2.scc
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup.vdproj
BSEtunesSetup.vdproj
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.ThreadedShell.DLL
BSE.Windows.Forms.DLL
lame_enc.dll
MySQL.chm.zip
MySQL.chm
MySqlCreateDataBase5x.sql.zip
using System;
using System.Runtime.InteropServices;
using System.Timers;
using BSE.Platten.Audio.Properties;
using System.Globalization;

namespace BSE.Platten.Audio
{
	/// <summary>
	/// Zusammenfassung f�r CWinamp.
	/// </summary>
	public class Winamp : Player
	{
        #region Events

        internal event EventHandler<PlayStateChangeEventArgs> PlayStateChange;

        #endregion

        #region Konstanten

        private const string m_lpClassName		= "Winamp v1.x";
		private const string m_strTtlEnd		= " - Winamp";
		
		//Windows Const
		private const uint WM_COMMAND = 0x111;
		private const uint WM_COPYDATA = 0x4A;
		private const uint WM_USER = 0x400;
		
		//WM_USER Messages
		private const int IPC_PLAYFILE = 100;
		private const int IPC_DELETE = 101;
		private const int IPC_ISPLAYING = 104;
		private const int IPC_GETOUTPUTTIME	= 105;
        private const int IPC_JUMPTOTIME = 106;
        private const int IPC_SETPLAYLISTPOS = 121;
        private const int IPC_GETLISTLENGTH = 124;
        private const int IPC_GETLISTPOS = 125;

		//WM_Command
		private const int IPC_CLOSE = 40001;
		private const int IPC_PLAY = 40045;
		private const int IPC_PLAUSE = 40046;
		private const int IPC_STOP = 40047;

		#endregion

		#region FieldsPrivate
		
		private COPYDATASTRUCT m_copyDataStruct;
		private string m_strPlayerFileName;
		private System.Timers.Timer m_tmrMonitoring;
        private PlayState m_ePlayState;
        private int m_iPlaylistPosition;
		
		#endregion
		
		#region Properties
        /// <summary>
        /// The count property retrieves the number of media items in the playlist.
        /// </summary>
        public override int Count
        {
            get
            {
                IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
                return NativeMethods.SendMessage(hWnd, WM_USER, 0, IPC_GETLISTLENGTH);
            }
        }
        /// <summary>
        /// Gets the name of the used audioplayer
        /// </summary>
        public override string Name
        {
            get { return "Nullsoft Winamp"; }
        }
        internal string PlayerFileName
		{
			get {return this.m_strPlayerFileName;}
			set {this.m_strPlayerFileName = value;}
		}
        /// <summary>
        /// The PlaylistPosition property retrieves the current position of the media item in the playlist.
        /// </summary>
        internal int PlaylistPosition
        {
            get { return this.m_iPlaylistPosition; }
            set { this.m_iPlaylistPosition = value; }
        }
		#endregion

		#region MethodsPublic

		public Winamp()
		{
            this.PlayStateChange += new EventHandler<PlayStateChangeEventArgs>(this.PlayStateChanged);
            this.m_tmrMonitoring = new System.Timers.Timer();
			this.m_tmrMonitoring.Interval = 1000;
			this.m_tmrMonitoring.AutoReset = true;
			this.m_tmrMonitoring.Elapsed += new System.Timers.ElapsedEventHandler(this.m_tmrMonitoring_Elapsed);
			this.m_tmrMonitoring.Enabled = false;
		}

        public Winamp(WinampConfigurationData winampConfigurationObject) : this()
        {
            if (winampConfigurationObject == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.IDS_ArgumentNullException,
                    "winampConfigurationObject"));
            }
            this.m_strPlayerFileName = winampConfigurationObject.FileName;
        }

        public Winamp(string playerFileName) : this()
        {
            this.m_strPlayerFileName = playerFileName;
        }

		public override void Play()
		{
            if (IsPlaying(IPC_PLAY) == true)
			{
				this.m_tmrMonitoring.Enabled = true;
			}
		}

		public override void Play(string strFile, BSE.Platten.Audio.PlayMode mode)
		{
			try
			{
				if (IsRunning() == false)
				{
					this.StartPlayer();
					while (IsStarting() == false);
					OnPlayerStarted(this, new PlayerEventArgs(true));
				}
				this.Mode = mode;
				this.ClearPlayList();
                try
                {
                    if (CCheckFile.FileExists(strFile) == true)
                    {
                        this.EnqueueFile(strFile);
                        if (IsPlaying(IPC_PLAY) == true)
                        {
                            this.m_tmrMonitoring.Enabled = true;
                        }
                    }
                }
                catch (System.IO.FileNotFoundException)
                {
                    throw;
                }
			}
			catch (Exception)
			{
				throw;
			}
		}

		public override void Play(string[] strFiles, BSE.Platten.Audio.PlayMode mode)
		{
			try
			{
                if (strFiles == null)
                {
                    throw new ArgumentNullException(
                        string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.IDS_ArgumentNullException,"strFiles"));
                }
                if (IsRunning() == false)
				{
					this.StartPlayer();
					while (IsStarting() == false);
					OnPlayerStarted(this, new PlayerEventArgs(true));
				}
				this.Mode = mode;
				int iFileCount = strFiles.Length;
				string[] files = strFiles;
			
				this.ClearPlayList();

				for (int i = 0; i < iFileCount; i++)
				{
					string fileName = files[i];
                    try
                    {
                        if (CCheckFile.FileExists(fileName) == true)
                        {
                            EnqueueFile(fileName);
                        }
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        throw;
                    }
				}
                if (IsPlaying(IPC_PLAY) == true)
				{
                    this.PlaylistPosition = 0;
                    this.m_tmrMonitoring.Enabled = true;
				}
			}
			catch (Exception)
			{
				throw;
			}
		}

		public override void Load()
		{
			if (IsRunning() == false)
			{
				this.StartPlayer();
				while (IsStarting() == false);
				OnPlayerStarted(this, new PlayerEventArgs(true));
			}
		}

		public override void Close()
		{
			this.Stop();
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
			{
                this.PlayStateChange -= new EventHandler<PlayStateChangeEventArgs>(this.PlayStateChanged);
                NativeMethods.SendMessage(hWnd, WM_COMMAND, IPC_CLOSE, 0);
			}
		}

		public override void Pause()
		{
			if (IsRunning())
			{
                IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
                if (hWnd.Equals(IntPtr.Zero) == false)
                {
                    NativeMethods.PostMessage(hWnd, WM_COMMAND, IPC_PLAUSE, 0);
                }
			}
		}

		public override void Stop()
		{ 
			if (IsRunning() == false)
			{
				return;
			}
			if (this.m_tmrMonitoring.Enabled)
			{
				this.m_tmrMonitoring.Enabled = false;
                this.m_ePlayState = PlayState.Stopped;
				OnPlayerStopped(this, new PlayerEventArgs(BSE.Platten.Audio.PlayMode.None));
			}
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                NativeMethods.PostMessage(hWnd, WM_COMMAND, IPC_STOP, 0);
            }

		}
        /// <summary>
        /// Gets the new position in the playlist.
        /// </summary>
        /// <returns>current playlist position</returns>
        public override int GetPlaylistPosition()
        {
            int iPlayListPosition = 0;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                iPlayListPosition = NativeMethods.SendMessage(hWnd, WM_USER, 0, IPC_GETLISTPOS);
            }
            return iPlayListPosition;
        }
        /// <summary>
        /// Sets the new position in the playlist.
        /// </summary>
        /// <param name="iPosition">new playlist position</param>
        public override void SetPlaylistPosition(int iPosition)
        {
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                NativeMethods.SendMessage(hWnd, WM_USER, iPosition, IPC_SETPLAYLISTPOS);
                if (IsPlaying(IPC_PLAY) == true)
                {
                    OnPlayerPlays(this, new PlayerEventArgs());
                }
            }
        }

		public override void ClearPlayList()
		{
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                NativeMethods.SendMessage(hWnd, WM_USER, 0, IPC_DELETE);
            }
		}
        /// <summary>
        /// Sets the current position in the media item in seconds from the beginning.
        /// </summary>
        /// <param name="iCurrentPostion">current position in seconds</param>
        public override void SetTrackPosition(int iCurrentPostion)
        {
            if (iCurrentPostion > 0)
            {
                IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
                if (hWnd.Equals(IntPtr.Zero) == false)
                {
                    NativeMethods.SendMessage(hWnd, WM_USER, iCurrentPostion * 1000, IPC_JUMPTOTIME);
                }
            }
        }
        /// <summary>
        /// Gets the current position in the media item in seconds from the beginning.
        /// </summary>
        /// <returns>current position in seconds</returns>
		public override int GetTrackPosition()
		{
            int iTrackPosition = 0;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                iTrackPosition = NativeMethods.SendMessage(hWnd, WM_USER, 0, IPC_GETOUTPUTTIME) / 1000;
            }
            return iTrackPosition;
		}
        /// <summary>
        /// Gets the duration in seconds of the current media item
        /// </summary>
        /// <returns>the duration in seconds</returns>
		public override int GetTrackLength()
		{
            int iTrackLenght = 0;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                iTrackLenght = NativeMethods.SendMessage(hWnd, WM_USER, 1, IPC_GETOUTPUTTIME);
            }
            return iTrackLenght;
		}

		public override string GetSongTitle()
		{
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
			{
				string lpText = new string((char) 0, 100);
                int intLength = NativeMethods.GetWindowText(hWnd, lpText, lpText.Length);
		
				if ((intLength <= 0) || (intLength > lpText.Length))
				{
                    return UnknownTitle;
				}
				string strTitle = lpText.Substring(0, intLength);
				int intName = strTitle.IndexOf(m_strTtlEnd);
				int intLeft = strTitle.IndexOf("[");
				int intRight = strTitle.IndexOf("]");

				if ((intName >= 0) && (intLeft >= 0) && (intName < intLeft) &&
					(intRight >= 0) && (intLeft + 1 < intRight))
					return strTitle.Substring(intLeft + 1, intRight - intLeft - 1);

				if ((strTitle.EndsWith(m_strTtlEnd)) && (strTitle.Length > m_strTtlEnd.Length))
					strTitle = strTitle.Substring(0, strTitle.Length - m_strTtlEnd.Length);

				int intDot = strTitle.IndexOf(".");
				if ((intDot > 0) && IsNumeric(strTitle.Substring(0, intDot)))
					strTitle = strTitle.Remove(0, intDot + 1);

				return strTitle.Trim();
			}
			else
			{
				return string.Empty;
			}
		}
		
		#endregion

		#region MethodsProtected
		#endregion

		#region MethodsPrivate

        private void PlayStateChanged(object sender, PlayStateChangeEventArgs e)
        {
            switch (e.PlayState)
            {
                case PlayState.Ended:
                    OnSongEnded(sender, new PlayerEventArgs(this.Mode));
                    break;
                case PlayState.Stopped:
                    OnPlayerStopped(sender, new PlayerEventArgs(this.Mode));
                    break;
                case PlayState.Playing:
                    OnPlayerPlays(sender, new PlayerEventArgs(this.Mode));
                    break;
                case PlayState.Paused:
                    OnPlayerPaused(sender, new PlayerEventArgs());
                    break;
                case PlayState.Closed:
                    OnPlayerClosed(sender, new PlayerEventArgs(this.Mode));
                    break;
            }
        }
        /// <summary>
        /// sent as a WM_COPYDATA, with IPC_PLAYFILE as the dwData, and the string to play
        /// as the lpData. Just enqueues, does not clear the playlist or change the playback
        /// state.
        /// </summary>
        /// <param name="file">file for enqueuing</param>
        private void EnqueueFile(string file)
		{
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                m_copyDataStruct.dwData = (IntPtr)IPC_PLAYFILE;
                m_copyDataStruct.lpData = file;
                m_copyDataStruct.cbData = file.Length + 1;
                NativeMethods.SendMessage(hWnd, WM_COPYDATA, IntPtr.Zero, ref m_copyDataStruct);
            }
		}

        private static bool IsNumeric(string Value)
		{
			try 
			{
				double.Parse(Value);
				return true;
			}
			catch
			{
				return false;
			}
		}

		private void StartPlayer()
		{
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == true)
			{
                if (String.IsNullOrEmpty(this.m_strPlayerFileName) == true)
                {
                    throw new System.IO.FileNotFoundException(
                        Resources.IDS_WinampNotFoundException,this.m_strPlayerFileName);
                }
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.EnableRaisingEvents = false;
                process.StartInfo.FileName = this.m_strPlayerFileName;
                process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
                process.StartInfo.UseShellExecute = true;
                process.Start();
			}
		}

		private static bool IsStarting()
		{
			bool bIsStarting = false;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
			{
                bIsStarting = true;
			}
			return bIsStarting;
		}

		private static bool IsRunning()
		{
			bool bIsRunning = false;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
			{
				bIsRunning = true;
			}
			return bIsRunning;
		}

		private static bool IsPlaying(int action)
		{
            bool bIsPlaying = false;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                if (NativeMethods.PostMessage(hWnd, WM_COMMAND, action, 0) > 0)
                {
                    bIsPlaying = true;
                }
            }
            return bIsPlaying;
		}
        /// <summary>
        /// If it returns 1, it is playing. if it returns 3, it is paused,
        /// if it returns 0, it is not playing.
        /// </summary>
        /// <returns>int 1 playing, int 3 pause, 0 not playing</returns>
        private static int GetStatus()
		{
            int iStatus = 0;
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == false)
            {
                iStatus = NativeMethods.SendMessage(hWnd, WM_USER, 0, IPC_ISPLAYING);
            }
            return iStatus;
		}
		private void m_tmrMonitoring_Elapsed(object source, System.Timers.ElapsedEventArgs e)
		{
            IntPtr hWnd = NativeMethods.FindWindow(m_lpClassName, null);
            if (hWnd.Equals(IntPtr.Zero) == true)
			{
                this.m_tmrMonitoring.Enabled = false;
				return;
			}
            
            int iCurrentPlaylistPosition = this.GetPlaylistPosition();
            if (iCurrentPlaylistPosition.Equals(this.PlaylistPosition) == false)
            {
                if (this.Mode == PlayMode.CD)
                {
                    //Wird ein Album abgespielt, dann wird hier der Wechsel der Tracks
                    //festgestellt. Ein Statuswechsel wird nicht erreicht
                    this.PlaylistPosition = iCurrentPlaylistPosition;
                    if (IsPlaying(IPC_PLAY) == true)
                    {
                        this.m_ePlayState = PlayState.Undefined;
                        return;
                    }
                }
            }
            PlayState ePlayState = (PlayState)GetStatus();
            if (ePlayState == this.m_ePlayState)
			{
				return;
			}
            //Der Timer wird angehalten
            this.m_tmrMonitoring.Enabled = false;
            this.m_ePlayState = ePlayState;
            switch (ePlayState)
			{
				case PlayState.Stopped:
                    if (hWnd.Equals(IntPtr.Zero))
					{
                        PlayStateChanged(this,new PlayStateChangeEventArgs(PlayState.Closed));
						return;
					}
                    if (this.Mode != PlayMode.CD)
                    {
                        PlayStateChanged(this, new PlayStateChangeEventArgs(PlayState.Ended));
                    }
                    else
                    {
                        //Wenn ein Album gespielt wird, soll hier gestoppt werden
                        //nur nach Beendigung des letzten Tracks wird dieser Code erreicht
                        PlayStateChanged(this, new PlayStateChangeEventArgs(PlayState.Stopped));
                    }
					break;
                case PlayState.Playing:
                    PlayStateChanged(this,new PlayStateChangeEventArgs(PlayState.Playing));
					break;
                case PlayState.Paused:
                    PlayStateChanged(this,new PlayStateChangeEventArgs(PlayState.Paused));
					break;
			}
            //Der Timer wird wieder eingeschaltet
            this.m_tmrMonitoring.Enabled = true;
		}

		#region Struct COPYDATASTRUCT

		[StructLayout(LayoutKind.Sequential)]
		internal struct COPYDATASTRUCT
		{
			public IntPtr dwData;
			public int cbData;
			[MarshalAs(UnmanagedType.LPStr)] public string lpData;
		}
		
		#endregion

        #region class NativeMethods

        internal static class NativeMethods
        {
            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int SendMessage(IntPtr hwnd, uint wMsg, IntPtr wParam, ref COPYDATASTRUCT copyDataStruct);

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int GetWindowText(IntPtr hWnd, string lpString, int nMaxCount);

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int PostMessage(IntPtr hWnd, uint wMsg, int wParam, int lParam);
        }
        
        #endregion
        
        #endregion
    }

    public class PlayStateChangeEventArgs : EventArgs
    {
        #region FieldsPrivate

        private PlayState m_ePlayState;

        #endregion

        #region Properties

        public PlayState PlayState
        {
            get { return this.m_ePlayState; }
        }

        #endregion

        #region MethodsPublic

        public PlayStateChangeEventArgs(PlayState m_ePlayState)
		{
            this.m_ePlayState = m_ePlayState;
		}

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Eichkorn

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid