Ejemplo n.º 1
0
        public void ProcessFiles()
        {
            var files = _folderInteractor.GetFilesForFolder(_folderToWatch).Shuffle();

            foreach (var file in files)
            {
                if (SupportedFileTypes.IsSupportedFileType(file))
                {
                    var filePath = file;
                    if (SupportedFileTypes.RequiresTranscoding(file))
                    {
                        var newFile = _transcoder.Transcode(filePath);
                        _folderInteractor.DeleteFile(filePath);
                        filePath = newFile;
                    }

                    var musicInfo = _musicInfoReader.GetInfoForFile(filePath);
                    var album     = string.IsNullOrEmpty(musicInfo.Album) ? UNKNOWN_ALBUM_NAME : musicInfo.Album;
                    var artist    = string.IsNullOrEmpty(musicInfo.Artist) ? UNKNOWN_ARTIST_NAME : musicInfo.Artist;

                    musicInfo.FullPath = MoveToLibraryFolder(filePath, artist, album);
                    _library.AddOrUpdateMusicInLibrary(musicInfo);
                }
            }
        }
Ejemplo n.º 2
0
        private void PlayInThread(object data)
        {
            string filename = (string)data;

            _waveOutDevice = new WaveOut();
            WaveChannel32 inputStream = null;
            WaveStream    mp3Reader   = null;

            try
            {
                if (SupportedFileTypes.CanBePlayed(filename))
                {
                    mp3Reader = new Mp3FileReader(filename);

                    inputStream = new WaveChannel32(mp3Reader);
                }
                else
                {
                    throw new InvalidOperationException("Unsupported extension");
                }

                _waveOutDevice.Init(inputStream);
                _waveOutDevice.Volume           = _volume;
                _waveOutDevice.PlaybackStopped += _waveOutDevice_PlaybackStopped;
                _waveOutDevice.Play();

                Log.Debug("Playing " + filename);

                Thread.Sleep(mp3Reader.TotalTime);
            }
            catch (Exception exc)
            {
                Log.Debug("Error while playing song " + filename + ":" + exc.ToString());
            }
            finally
            {
                _waveOutDevice.Stop();
                if (mp3Reader != null)
                {
                    mp3Reader.Close();
                }

                if (inputStream != null)
                {
                    inputStream.Close();
                }

                _waveOutDevice.Dispose();
            }
        }
Ejemplo n.º 3
0
        public List <MusicInfo> CrawlDirectory(string audioDirectory)
        {
            var result = new List <MusicInfo>();

            var musicInfoReader = new MusicInfoReader();
            var files           = Directory.GetFiles(audioDirectory).Where(X => SupportedFileTypes.IsSupportedFileType(X)).ToArray();


            foreach (var file in files)
            {
                result.Add(musicInfoReader.GetInfoForFile(file));
            }

            //look for subdirectories, recursively get files
            var directories = Directory.GetDirectories(audioDirectory);

            foreach (var directory in directories)
            {
                result.AddRange(CrawlDirectory(directory));
            }

            return(result);
        }