Click here to Skip to main content
12,457,938 members (56,503 online)
Click here to Skip to main content

Stats

39.3K views
3.9K downloads
57 bookmarked
Posted

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
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
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
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
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
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
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.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
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
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
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
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
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
using System;
using System.Collections;
using System.ComponentModel;

using BSE.Platten.BO;
using System.Globalization;
using BSE.Platten.Audio.Properties;

namespace BSE.Platten.Audio
{
	/// <summary>
	/// Zusammenfassung f�r CPlayerManager.
	/// </summary>
	public class CPlayerManager : Component
	{
		
		#region EventsPublic

		public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerManagerTrackChanged;
        public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerManagerSongFinished;
        public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerStarted;
        public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerManagerStopped;
        public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerManagerPlays;
        public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerManagerPaused;
        public event EventHandler<PlayerManagerStatusChangedEventArgs> PlayerManagerClosed;

		#endregion

		#region FieldsPrivate
		
		private Player m_player;
        private UsedPlayer m_usedPlayer;
        private PlayMode m_playMode;
        private CTrackCollection m_trackCollection;
        private bool m_bHasPlayerStarted;
		
		#endregion

        #region Properties
        /// <summary>
        /// Gets the current played audio <see cref="CTrack"/>.
        /// </summary>
        public BSE.Platten.BO.CTrack CurrentTrack
        {
            get
            {
                if (this.TrackCollection != null)
                {
                    return this.TrackCollection.CurrentTrack;
                }
                return null;
            }
        }
        /// <summary>
        /// Checks if the next track is available.
        /// </summary>
        public bool IsNextTrackAvailable
        {
            get
            {
                if (this.TrackCollection != null)
                {
                    return this.TrackCollection.IsNextTrackAvailable;
                }
                return false;
            }
        }
        /// <summary>
        /// Checks if a previous track is available.
        /// </summary>
        /// <returns></returns>
        public bool IsPreviousTrackAvailable
        {
            get
            {
                if (this.TrackCollection != null)
                {
                    return this.TrackCollection.IsPreviousTrackAvailable;
                }
                return false;
            }
        }
        public bool HasPlayerStarted
        {
            get { return this.m_bHasPlayerStarted; }
            set { this.m_bHasPlayerStarted = value; }
        }

        public UsedPlayer UsedPlayer
        {
            get { return this.m_usedPlayer; }
        }
        /// <summary>
        /// The count property retrieves the number of media items in the playlist.
        /// </summary>
        public int Count
        {
            get
            {
                int iCount = -1;
                if (this.m_playMode == PlayMode.CD)
                {
                    iCount = this.m_player.Count;
                }
                if (this.m_playMode == PlayMode.Playlist)
                {
                    iCount = this.m_trackCollection.Count;
                }
                if (this.m_playMode == PlayMode.Random)
                {
                    iCount = this.m_trackCollection.Count;
                }
                return iCount;
            }
        }

        public CTrackCollection TrackCollection
        {
            get { return this.m_trackCollection; }
            set { this.m_trackCollection = value; }
        }
        /// <summary>
        /// Gets the PlayMode in which the player plays.
        /// </summary>
        public PlayMode PlayMode
        {
            get { return this.m_playMode; }
        }
        /// <summary>
        /// Gets the PlayState of the used Audio Player.
        /// </summary>
        public PlayState PlayState
        {
            get
            {
                if (this.m_player == null)
                {
                    return PlayState.Closed;
                }
                else
                {
                    return this.m_player.PlayState;
                }
            }
        }
        #endregion

        #region MethodsPublic

        public CPlayerManager()
		{
		}

        public void LoadPlayer(BSE.Configuration.CConfiguration configuration)
        {
            UsedPlayerConfigurationData usedPlayerConfigurationObject =
                CPlayerConfigurationControl.GetConfiguration(configuration) as UsedPlayerConfigurationData;

            if (usedPlayerConfigurationObject != null)
            {
                UsedPlayer eUsedPlayer = usedPlayerConfigurationObject.UsedPlayer;
                if (eUsedPlayer != this.m_usedPlayer)
                {
                    this.Close();
                }

                this.m_usedPlayer = eUsedPlayer;
                switch (this.m_usedPlayer)
                {
                    case UsedPlayer.None:
                        break;
                    case UsedPlayer.MediaPlayer:
                        this.m_player = new MediaPlayer();
                        break;
                    case UsedPlayer.Winamp:
                        this.m_player = new Winamp((WinampConfigurationData)CWinampConfigurationControl.GetConfiguration(configuration));
                        break;
                }
                if (this.m_player != null)
                {
                    this.m_player.PlayerStarted += new EventHandler<PlayerEventArgs>(this.m_player_PlayerStarted);
                    this.m_player.PlayerPlays += new EventHandler<PlayerEventArgs>(this.m_player_PlayerPlays);
                    this.m_player.PlayerClosed += new EventHandler<PlayerEventArgs>(this.m_player_PlayerClosed);
                    this.m_player.PlayerPaused += new EventHandler<PlayerEventArgs>(this.m_player_PlayerPaused);
                    this.m_player.PlayerStopped += new EventHandler<PlayerEventArgs>(this.m_player_PlayerStopped);
                    this.m_player.SongEnded += new EventHandler<PlayerEventArgs>(this.m_player_SongEnded);
                    this.m_player.Load();
                }
            }
        }

		public void Stop()
		{
            if (this.m_player != null)
			{
				this.m_player.Stop();
			}
		}

		public void Pause()
		{
			if (this.m_player != null)
			{
				this.m_player.Pause();
			}
		}

		public void Play()
		{
			if (this.m_player != null)
			{
				this.m_player.Play();
			}
		}
        /// <summary>
        /// Close the player and cleanup the resources
        /// </summary>
		public void Close()
		{
			if (this.m_player != null)
			{
                this.m_player.Close();
			}
		}
        
        /// <summary>
        /// Plays the next track in the current track collection
        /// </summary>
        /// <param name="eMode">The mode in which the tracks have to play</param>
        public void PlayNextTrack(PlayMode eMode)
        {
            if (this.m_trackCollection != null)
            {
                switch (eMode)
                {
                    case PlayMode.Random:
                    case PlayMode.Playlist:
                        if (this.m_trackCollection.MoveNext() == true)
                        {
                            CTrack currentTrack = this.m_trackCollection.CurrentTrack;
                            if (currentTrack != null)
                            {
                                Play(currentTrack, eMode);
                            }
                        }
                        break;
                }
            }
        }
        public void PlayPreviousTrack(PlayMode eMode)
        {
            if (this.m_trackCollection != null)
            {
                switch (eMode)
                {
                    case PlayMode.Random:
                    case PlayMode.Playlist:
                        if (this.m_trackCollection.MovePrevious() == true)
                        {
                            CTrack currentTrack = this.m_trackCollection.CurrentTrack;
                            if (currentTrack != null)
                            {
                                Play(currentTrack, eMode);
                            }
                        }
                    break;
                }
            }
        }
        /// <summary>
        /// Sets the new trackcollection if the filtersettings have to change
        /// </summary>
        /// <param name="trackCollection">A collection of tracks for playing</param>
        public void SetTracksToPlay(BSE.Platten.BO.CTrackCollection trackCollection)
		{
            this.m_trackCollection = trackCollection;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="trackToPlay">A track for playing</param>
        /// <param name="eMode">The mode in which the tracks have to play</param>
		public void PlayTrack(BSE.Platten.BO.CTrack trackToPlay,BSE.Platten.Audio.PlayMode eMode)
		{
            if (this.m_player == null)
            {
                throw new ArgumentException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.CPlayerManagerNoPlayerException));
            }
            if (trackToPlay == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.IDS_ArgumentNullException,"trackToPlay"));
            }
            this.m_playMode = eMode;
			this.Stop();
            if (CCheckFile.FileExists(trackToPlay.FileFullName))
			{
                this.m_player.Play(trackToPlay.FileFullName,this.m_playMode);
				OnPlayerManagerTrackChanged(new PlayerManagerStatusChangedEventArgs(trackToPlay,this.m_playMode));
			}
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="trackCollection">A collection of tracks for playing</param>
        /// <param name="eMode">The mode in which the tracks have to play</param>
		public void PlayTracks(BSE.Platten.BO.CTrackCollection trackCollection,BSE.Platten.Audio.PlayMode eMode)
		{
			if (this.m_player == null)
            {
                throw new ArgumentException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.CPlayerManagerNoPlayerException));
            }
            this.m_playMode = eMode;
            this.m_trackCollection = trackCollection;
            this.m_trackCollection.Reset();
            this.Stop();
            
            switch (eMode)
            {
                case PlayMode.Playlist:
                    if (this.m_trackCollection.MoveNext() == true)
                    {
                        CTrack currentTrack = this.m_trackCollection.CurrentTrack;
                        if (currentTrack != null)
                        {
                            this.Play(currentTrack, this.m_playMode);
                        }
                    }
                    break;
                case PlayMode.Random:
                    this.m_trackCollection = GetRandomTrackCollection();
                    if (this.m_trackCollection.MoveNext() == true)
                    {
                        CTrack currentTrack = this.m_trackCollection.CurrentTrack;
                        if (currentTrack != null)
                        {
                            this.Play(currentTrack, this.m_playMode);
                        }
                    }
                    break;
                case PlayMode.CD:
                    ArrayList aTracks = new ArrayList();
                    IEnumerator enumerator = this.m_trackCollection.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        CTrack track = enumerator.Current as CTrack;
                        if (track != null)
                        {
                            if (String.IsNullOrEmpty(track.FileFullName) == false)
                            {
                                aTracks.Add(track.FileFullName);
                            }
                        }
                    }
                    if (aTracks.Count > 0)
                    {
                        String[] strFiles = new String[aTracks.Count];
                        aTracks.CopyTo(strFiles);
                        CTrack track = this.m_trackCollection[0] as CTrack;
                        if (track != null)
                        {
                            this.m_player.Play(strFiles, this.m_playMode);
                            //Wenn der Mode des �bergebenen Arrays == Mode.CD
                            //wird der Title des 1. Tracks mit string.Empty �berschrieben
                            CTrack tmpTrack = track.Clone() as CTrack;
                            tmpTrack.LiedId = 0;
                            tmpTrack.Title = string.Empty;
                            OnPlayerManagerTrackChanged(new PlayerManagerStatusChangedEventArgs(tmpTrack, this.m_playMode));
                        }
                    }
                    break;
            }
		}
        /// <summary>
        /// Gets the new position in the playlist.
        /// </summary>
        /// <returns>current playlist position</returns>
        public int GetPlaylistPosition()
        {
            int iPosition = -1;
            if (this.m_playMode == PlayMode.CD)
            {
                iPosition = this.m_player.GetPlaylistPosition();
            }
            if (this.m_playMode == PlayMode.Playlist)
            {
                iPosition = this.m_trackCollection.Index;
            }
            return iPosition;
        }
        /// <summary>
        /// Sets the new position in the playlist.
        /// </summary>
        /// <param name="iPosition">new playlist position</param>
        public void SetPlaylistPosition(int iPosition)
        {
            if (this.m_player != null)
            {
                this.m_player.SetPlaylistPosition(iPosition);
            }
        }
        /// <summary>
        /// Sets the current position in the media item in seconds from the beginning.
        /// </summary>
        /// <param name="iCurrentPostion">current position in seconds</param>
        public void SetTrackPosition(int iCurrentPostion)
        {
            if (this.m_player != null)
            {
                this.m_player.SetTrackPosition(iCurrentPostion);
            }
        }
        /// <summary>
        /// Gets the current position in the media item in seconds from the beginning.
        /// </summary>
        /// <returns>current position in seconds</returns>
        public int GetTrackPosition()
        {
            if (this.m_player != null)
            {
                return this.m_player.GetTrackPosition();
            }
            return -1;
        }
        /// <summary>
        /// Gets the duration in seconds of the current media item in HH:MM:SS format.
        /// </summary>
        /// <param name="iTrackLength">the duration in seconds</param>
        /// <returns>the duration in HH:MM:SS format</returns>
        public static string GetTrackDurationAsString(int iTrackLength)
        {
            TimeSpan timeSpan = new TimeSpan(0, 0, iTrackLength);
            return timeSpan.ToString();
        }
        /// <summary>
        /// Gets the duration in seconds of the current media item
        /// </summary>
        /// <returns>the duration in seconds</returns>
        public int GetTrackLength()
        {
            return this.m_player.GetTrackLength();
        }
        public string GetSongTitle()
        {
            return this.m_player.GetSongTitle();
        }
        public static int GetRandomIndex(int iCounter)
		{
			Random random = new Random();
			return random.Next(iCounter);
		}
		#endregion

		#region MethodsProtected
		
		protected virtual void OnPlayerManagerTrackChanged(PlayerManagerStatusChangedEventArgs e)
		{
			if (this.PlayerManagerTrackChanged != null)
			{
				this.PlayerManagerTrackChanged(this,e);
			}
		}

        protected virtual void OnPlayerManagerSongFinished(PlayerManagerStatusChangedEventArgs e)
        {
            if (this.PlayerManagerSongFinished != null)
            {
                this.PlayerManagerSongFinished(this, e);
            }
        }

		protected virtual void OnPlayerStarted(PlayerManagerStatusChangedEventArgs e)
		{
			if (this.PlayerStarted != null)
			{
				this.PlayerStarted(this,e);
			}
		}

		protected virtual void OnPlayerManagerStopped(PlayerManagerStatusChangedEventArgs e)
		{
			if (this.PlayerManagerStopped != null)
			{
				this.PlayerManagerStopped(this,e);
			}
		}

		protected virtual void OnPlayerManagerPaused(PlayerManagerStatusChangedEventArgs e)
		{
			if (this.PlayerManagerPaused != null)
			{
				this.PlayerManagerPaused(this,e);
			}
		}

		protected virtual void OnPlayerManagerPlays(PlayerManagerStatusChangedEventArgs e)
		{
            if (this.PlayerManagerPlays != null)
			{
				this.PlayerManagerPlays(this,e);
			}
		}

		protected virtual void OnPlayerManagerClosed(PlayerManagerStatusChangedEventArgs e)
		{
			if (this.PlayerManagerClosed != null)
			{
				this.PlayerManagerClosed(this,e);
			}
		}
		
		#endregion

		#region MethodsPrivate
		
		private void m_player_PlayerStarted(object sender, PlayerEventArgs e)
		{
            this.HasPlayerStarted = e.PlayerHasStarted;
            OnPlayerStarted(new PlayerManagerStatusChangedEventArgs(e.PlayerHasStarted));
		}

		private void m_player_PlayerPlays(object sender, PlayerEventArgs e)
		{
			OnPlayerManagerPlays(new PlayerManagerStatusChangedEventArgs(e.PlayMode));
		}

		private void m_player_PlayerStopped(object sender, PlayerEventArgs e)
		{
			try
			{
				switch(e.PlayMode)
				{
					case PlayMode.None:
                    case PlayMode.Song:
					case PlayMode.CD:
                        OnPlayerManagerStopped(new PlayerManagerStatusChangedEventArgs());
						break;
					case PlayMode.Playlist:
                        if (this.m_trackCollection != null)
                        {
                            if (this.m_trackCollection.MoveNext() == true)
                            {
                                CTrack currentTrack = this.m_trackCollection.CurrentTrack;
                                if (currentTrack != null)
                                {
                                    Play(currentTrack, e.PlayMode);
                                }
                            }
                            else
                            {
                                OnPlayerManagerStopped(new PlayerManagerStatusChangedEventArgs());
                            }
                        }
						break;
                    case PlayMode.Random:
                        OnPlayerManagerStopped(new PlayerManagerStatusChangedEventArgs());
                        break;
				}
			}
			catch (Exception)
			{
				throw; 
			}
		}

		private void m_player_PlayerClosed(object sender, PlayerEventArgs e)
		{
			OnPlayerManagerClosed(new PlayerManagerStatusChangedEventArgs(e.PlayMode));
		}

		private void m_player_PlayerPaused(object sender, PlayerEventArgs e)
		{
			OnPlayerManagerPaused(new PlayerManagerStatusChangedEventArgs());
		}

        private void m_player_SongEnded(object sender, PlayerEventArgs e)
        {
            try
            {
                switch (e.PlayMode)
                {
                    case PlayMode.Song:
                        OnPlayerManagerStopped(new PlayerManagerStatusChangedEventArgs(this.m_playMode));
                        break;
                    case BSE.Platten.Audio.PlayMode.Random:
                    case PlayMode.Playlist:
                        OnPlayerManagerSongFinished(new PlayerManagerStatusChangedEventArgs(this.m_playMode));
                        if (this.m_trackCollection != null)
                        {
                            if (this.m_trackCollection.MoveNext() == true)
                            {
                                CTrack currentTrack = this.m_trackCollection.CurrentTrack;
                                if (currentTrack != null)
                                {
                                    Play(currentTrack, e.PlayMode);
                                }
                            }
                            else
                            {
                                //Wenn alle Tracks gespielt wurden wird der Player gestoppt
                                OnPlayerManagerStopped(new PlayerManagerStatusChangedEventArgs(this.m_playMode));
                            }
                        }
                        break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

		private void Play(BSE.Platten.BO.CTrack track,BSE.Platten.Audio.PlayMode mode)
		{
			this.Stop();
            try
            {
                if (CCheckFile.FileExists(track.FileFullName))
                {
                    this.m_player.Play(track.FileFullName, mode);
                    OnPlayerManagerTrackChanged(new PlayerManagerStatusChangedEventArgs(track, mode));
                }
            }
            catch (Exception)
            {
                throw;
            }
		}

        private CTrackCollection GetRandomTrackCollection()
        {
            CTrackCollection randomTrackCollection = null;

            CTrackCollection tempTrackCollection = new CTrackCollection();
            foreach (CTrack track in this.m_trackCollection)
            {
                tempTrackCollection.Add(track);
            }
            Random random = new Random(DateTime.Now.Millisecond);
            while (tempTrackCollection.Count > 0)
            {

                int iIndex = random.Next(tempTrackCollection.Count);
                if (randomTrackCollection == null)
                {
                    randomTrackCollection = new CTrackCollection(tempTrackCollection.Count);
                }
                CTrack track = tempTrackCollection[iIndex];
                randomTrackCollection.Add(track);
                tempTrackCollection.RemoveAt(iIndex);
            }
            tempTrackCollection = null;

            return randomTrackCollection;
        }

		#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