Пример #1
0
        /// <summary>
        /// Creates an IAudioFile object from the specified path.
        /// </summary>
        /// <param name="path">The full path of the file.</param>
        /// <param name="throwExceptionIfUnknown">if set to <c>true</c>, throws an exception if unknown file extension; otherwise, returns <c>null</c>.</param>
        public static IAudioFile Create(string path, bool throwExceptionIfUnknown)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            string     ext       = Path.GetExtension(path).ToLower();
            IAudioFile audioFile = null;

            if (ext == ".mp3" || ext == ".mp2")
            {
                audioFile = new Mpeg(path, false);
            }
            else if (ext == ".ogg")
            {
                audioFile = new OggVorbis(path);
            }
            else if (ext == ".flac" || ext == ".fla")
            {
                audioFile = new Flac(path);
            }
            else if (ext == ".mpc" || ext == ".mpp" || ext == ".mp+")
            {
                audioFile = new Musepack(path);
            }
            else if (ext == ".shn")
            {
                audioFile = new Shorten(path);
            }
            else if (ext == ".ape" || ext == ".mac")
            {
                audioFile = new MonkeysAudio(path);
            }
            else if (ext == ".m4a")
            {
                audioFile = new Mpeg4(path);
            }
            else if (ext == ".ofr")
            {
                audioFile = new OptimFrog(path);
            }
            else if (throwExceptionIfUnknown)
            {
                throw new NotSupportedException(string.Format("Extension '{0}' not supported", ext));
            }

            return(audioFile);
        }
Пример #2
0
        /// <summary>
        /// Creates an IAudioFile object from the specified path.
        /// </summary>
        /// <param name="path">The full path of the file.</param>
        /// <param name="throwExceptionIfUnknown">if set to <c>true</c>, throws an exception if unknown file extension; otherwise, returns <c>null</c>.</param>
        public static IAudioFile Create(string path, bool throwExceptionIfUnknown)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");

            string ext = Path.GetExtension(path).ToLower();
            IAudioFile audioFile = null;

            if (ext == ".mp3" || ext == ".mp2")
            {
                audioFile = new Mpeg(path, false);
            }
            else if (ext == ".ogg")
            {
                audioFile = new OggVorbis(path);
            }
            else if (ext == ".flac" || ext == ".fla")
            {
                audioFile = new Flac(path);
            }
            else if (ext == ".mpc" || ext == ".mpp" || ext == ".mp+")
            {
                audioFile = new Musepack(path);
            }
            else if (ext == ".shn")
            {
                audioFile = new Shorten(path);
            }
            else if (ext == ".ape" || ext == ".mac")
            {
                audioFile = new MonkeysAudio(path);
            }
            else if (ext == ".m4a")
            {
                audioFile = new Mpeg4(path);
            }
            else if (ext == ".ofr")
            {
                audioFile = new OptimFrog(path);
            }
            else if (throwExceptionIfUnknown)
            {
                throw new NotSupportedException(string.Format("Extension '{0}' not supported", ext));
            }

            return audioFile;
        }