示例#1
0
        public static TrackMetaInfo CreateFileInfo(string filePath)
        {
            try
            {
                TagLib.File tags = TagLib.File.Create(filePath);

                var ret = new TrackMetaInfo
                {
                    FileName = filePath,
                    FileSize = new FileInfo(filePath).Length,
                    Title    = tags.Tag.Title,
                    Album    = tags.Tag.Album,
                };

                if (tags.Tag.Performers != null &&
                    tags.Tag.Performers.Length != 0)
                {
                    ret.Artist = tags.Tag.Performers[0];
                }

                if (tags.Tag.Pictures.Length > 0)
                {
                    ret.CoverData = tags.Tag.Pictures[0].Data.ToArray();
                }

                return(ret);
            }
            catch (Exception)
            {
                return(new TrackMetaInfo());
            }
        }
示例#2
0
文件: Helper.cs 项目: SKKbySSK/Legato
        public static TrackInfo ReadTrackInfo()
        {
            var trackInfo = new TrackInfo();
            var meta      = new TrackMetaInfo();

            MemoryMappedFile mmf = null;

            try
            {
                mmf = MemoryMappedFile.OpenExisting(RemoteClassName, MemoryMappedFileRights.ReadWrite, HandleInheritability.Inheritable);
            }
            catch (FileNotFoundException)
            {
                throw new ApplicationException("CurrentTrackの取得に失敗しました。AIMPが起動されているかを確認してください。");
            }

            using (var memory = mmf.CreateViewStream(0, RemoteMapFileSize))
            {
                // 数値情報の読み取り
                meta.HeaderSize = _ReadToUInt32(memory);

                _ReadToUInt32(memory);
                trackInfo.BitRate     = _ReadToUInt32(memory);
                trackInfo.ChannelType = (ChannelType)_ReadToUInt32(memory);
                trackInfo.Duration    = _ReadToUInt32(memory);
                trackInfo.FileSize    = _ReadToUInt64(memory);

                meta.Mask = _ReadToUInt32(memory);

                trackInfo.SampleRate  = _ReadToUInt32(memory);
                trackInfo.TrackNumber = _ReadToUInt32(memory);

                meta.AlbumStringLength    = _ReadToUInt32(memory);
                meta.ArtistStringLength   = _ReadToUInt32(memory);
                meta.YearStringLength     = _ReadToUInt32(memory);
                meta.FilePathStringLength = _ReadToUInt32(memory);
                meta.GenreStringLength    = _ReadToUInt32(memory);
                meta.TitleStringLength    = _ReadToUInt32(memory);

                // ヘッダの終端まで移動
                memory.Position = meta.HeaderSize;

                // 文字列の読み取り
                var buffer = new byte[RemoteMapFileSize - meta.HeaderSize];
                memory.Read(buffer, 0, buffer.Length);
                var trackInfoString = Encoding.Unicode.GetString(buffer);

                using (var reader = new StringReader(trackInfoString))
                {
                    trackInfo.Album    = _Read(reader, meta.AlbumStringLength);
                    trackInfo.Artist   = _Read(reader, meta.ArtistStringLength);
                    trackInfo.Year     = _Read(reader, meta.YearStringLength);
                    trackInfo.FilePath = _Read(reader, meta.FilePathStringLength);
                    trackInfo.Genre    = _Read(reader, meta.GenreStringLength);
                    trackInfo.Title    = _Read(reader, meta.TitleStringLength);
                }
            }

            return(trackInfo);
        }
示例#3
0
        public void Load(string url)
        {
            CurrentMediaKind = MediaKind.None;

            FreeHandles();

            if (FormatHelpers.IsMidi(url) && File.Exists(_configuration.SoundFontPath))
            {
                BassMidi.DefaultFont = _configuration.SoundFontPath;
            }

            const BassFlags sourceflags = BassFlags.Decode | BassFlags.Loop | BassFlags.Float | BassFlags.Prescan;
            const BassFlags mixerflags  = BassFlags.MixerDownMix | BassFlags.MixerPositionEx | BassFlags.AutoFree;

            if (FormatHelpers.IsNetwork(url))
            {
                _sourceHandle    = Bass.CreateStream(url, 0, sourceflags, _callback, IntPtr.Zero);
                CurrentMediaKind = MediaKind.Network;
            }
            else if (FormatHelpers.IsCd(url))
            {
                (int drive, int track)cdInfo = FormatHelpers.ProcessCdUrl(url);
                _sourceHandle    = BassCd.CreateStream(cdInfo.drive, cdInfo.track, sourceflags);
                CurrentMediaKind = MediaKind.CDStream;
            }
            else if (FormatHelpers.IsTracker(url))
            {
                _sourceHandle    = Bass.MusicLoad(url, 0, 0, sourceflags);
                CurrentMediaKind = MediaKind.Tracker;
                MetaInfo         = TrackMetaInfoFactory.CreateTrackerInfo(url, _sourceHandle);
            }
            else
            {
                _sourceHandle    = Bass.CreateStream(url, 0, 0, sourceflags);
                CurrentMediaKind = MediaKind.File;
                MetaInfo         = TrackMetaInfoFactory.CreateFileInfo(url);
            }

            if (_sourceHandle == 0)
            {
                ExceptionFactory.Create(Bass.LastError, "File Load failed");
            }

            _sourceInfo  = Bass.ChannelGetInfo(_sourceHandle);
            _mixerHandle = BassMix.CreateMixerStream(_sourceInfo.Frequency, _sourceInfo.Channels, mixerflags);

            if (_mixerHandle == 0)
            {
                ExceptionFactory.Create(Bass.LastError, "Mixer failed");
            }

            if (!BassMix.MixerAddChannel(_mixerHandle, _sourceHandle, BassFlags.MixerDownMix))
            {
                ExceptionFactory.Create(Bass.LastError, "Channel mixing failed");
            }

            Bass.ChannelSetAttribute(_mixerHandle, ChannelAttribute.Volume, _lastvol);
            InitEq(ref _mixerHandle);
            Bass.ChannelPlay(_mixerHandle, false);
            IsPlaying = true;
            NotifyPropertyChanged(nameof(MetaInfo));
        }