Click here to Skip to main content
15,881,803 members
Articles / Desktop Programming / Windows Forms

BSEtunes

Rate me:
Please Sign up or sign in to vote.
4.67/5 (11 votes)
24 Apr 2010CPOL4 min read 64.4K   4.3K   58  
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
using System;
using System.IO;
using System.Windows.Forms;
using BSE.Platten.BO;
using BSE.Platten.Common;
using System.Globalization;
using BSE.Platten.Audio.Properties;

namespace BSE.Platten.Audio
{
	/// <summary>
	/// Summary description for CReadFiles.
	/// </summary>
	/// <remarks></remarks>
	public class ReadFiles : ReadDirectoriesAndFiles
	{
		#region FieldsPrivate
        private string m_strSearchPattern;
        #endregion

		#region MethodsPublic
		/// <summary>
        /// default constructor of the CReadFiles class.
		/// </summary>
        public ReadFiles(IWin32Window owner, string strSearchPattern, System.IO.DirectoryInfo directoryInfo)
            : base(owner, directoryInfo)
        {
            this.m_strSearchPattern = strSearchPattern;
            base.DirectoryInfo = directoryInfo;
            base.Thread =
                new System.Threading.Thread(
                new System.Threading.ThreadStart(this.GetFiles));
            base.Thread.Start();
        }
		#endregion

		#region MethodsPrivate
		
		private void GetFiles()
		{
			DirectoryInfo directory = new DirectoryInfo(base.DirectoryInfo.FullName);
			if (directory.Exists == true)
			{
				try
				{
                    FileInfo[] fileInfos = null;
                    if (string.IsNullOrEmpty(this.m_strSearchPattern) == true)
                    {
                        fileInfos = directory.GetFiles();
                    }
                    else
                    {
                        fileInfos = directory.GetFiles(this.m_strSearchPattern);
                    }

                    if ((fileInfos != null) && (fileInfos.Length > 0))
                    {
                        foreach (System.IO.FileInfo fileInfo in fileInfos)
                        {
                            System.Threading.Thread.Sleep(20);
                            OnReadFile(new ReadFilesEventArgs(fileInfo, null));
                            if ((string.Compare(fileInfo.Extension.ToLower(), AudioformatExtensions.Mp3) == 0) ||
                                (string.Compare(fileInfo.Extension.ToLower(), AudioformatExtensions.Wma) == 0))
                            {
                                AudioData audioData = new CWMFMediaData();
                                try
                                {
                                    AudioMetaData audioMetaData = audioData.GetMediaMetaData(fileInfo.FullName);
                                    if (audioMetaData != null)
                                    {

                                        audioMetaData.FullName = fileInfo.FullName;
                                        audioMetaData.Name = fileInfo.Name;
                                        audioMetaData.Extension = fileInfo.Extension;
                                        OnFoundFile(new ReadFilesEventArgs(fileInfo, audioMetaData));

                                    }
                                }
                                catch (Exception)
                                {
                                    string strMessage = String.Format(
                                        CultureInfo.CurrentCulture,
                                        Resources.IDS_ReadAudioFileException,
                                        fileInfo.FullName);

                                    DialogResult dialogResult = GlobalizedMessageBox.Show(
                                        base.Owner,
                                        strMessage,
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Error);
                                    if (dialogResult == DialogResult.No)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
					}
				}
				catch(Exception exception)
				{
					if (base.Thread.ThreadState != System.Threading.ThreadState.AbortRequested)
					{
                        if (GlobalizedMessageBox.Show(base.Owner, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
                        {
                            base.Thread.Abort();
                        }
					}
				}
			}
		}

    	#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)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions