/// <summary> /// Reads tags from a File. /// </summary> public static TagReader Read(string FileName) { Bass.Init(); var h = Bass.CreateStream(FileName, Flags: BassFlags.Prescan); TagReader result = null; if (h != 0) { result = Read(h); Bass.StreamFree(h); } else { h = Bass.MusicLoad(FileName, Flags: BassFlags.Prescan); if (h != 0) { result = Read(h); Bass.MusicFree(h); } } if (!string.IsNullOrWhiteSpace(result?.Title)) { result.Title = System.IO.Path.GetFileNameWithoutExtension(FileName); } return(result); }
/// <summary> /// Loads a file into the player. /// </summary> /// <param name="FileName">Path to the file to Load.</param> /// <returns><see langword="true"/> on succes, <see langword="false"/> on failure.</returns> public async Task <bool> LoadAsync(string FileName) { try { if (Handle != 0) { Bass.StreamFree(Handle); } } catch { } if (_dev != -1) { Bass.CurrentDevice = _dev; } var currentDev = Bass.CurrentDevice; if (currentDev == -1 || !Bass.GetDeviceInfo(Bass.CurrentDevice).IsInitialized) { Bass.Init(currentDev); } var h = await Task.Run(() => OnLoad(FileName)); if (h == 0) { return(false); } Handle = h; var tags = TagReader.Read(Handle); Title = !string.IsNullOrWhiteSpace(tags.Title) ? tags.Title : Path.GetFileNameWithoutExtension(FileName); Artist = tags.Artist; Album = tags.Album; InitProperties(); MediaLoaded?.Invoke(h); OnPropertyChanged(""); return(true); }
/// <summary> /// Reads tags from a <paramref name="Channel"/>. /// </summary> public static TagReader Read(int Channel) { var result = new TagReader(); var info = Bass.ChannelGetInfo(Channel); switch (info.ChannelType) { case ChannelType.MP1: case ChannelType.MP2: case ChannelType.MP3: if (result.ReadID3v2(Channel)) { } else if (result.ReadID3v1(Channel)) { } else if (result.ReadApe(Channel)) { } else if (result.ReadBWF(Channel)) { } break; case ChannelType.OGG: if (result.ReadOgg(Channel)) { } else if (result.ReadApe(Channel)) { } break; case ChannelType.MP4: case ChannelType.AAC: if (result.ReadMp4(Channel)) { } else if (result.ReadID3v2(Channel)) { } else if (result.ReadApe(Channel)) { } else if (result.ReadOgg(Channel)) { } break; case ChannelType.Wave: case ChannelType.WavePCM: case ChannelType.WaveFloat: if (result.ReadRiffInfo(Channel)) { } else if (result.ReadBWF(Channel)) { } else if (result.ReadID3v2(Channel)) { } break; case ChannelType.DSD: result.Title = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.DSDTitle)); result.Artist = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.DSDArtist)); break; case ChannelType.MOD: result.Title = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.MusicName)); result.Artist = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.MusicAuth)); result.Comment = Marshal.PtrToStringAnsi(Bass.ChannelGetTags(Channel, TagType.MusicMessage)); break; default: if (result.ReadApe(Channel)) { } else if (result.ReadOgg(Channel)) { } else if (result.ReadID3v2(Channel)) { } else if (result.ReadID3v1(Channel)) { } break; } if (string.IsNullOrWhiteSpace(result.Lyrics)) { var ptr = Bass.ChannelGetTags(Channel, TagType.Lyrics3v2); if (ptr != IntPtr.Zero) { result.Lyrics = Marshal.PtrToStringAnsi(ptr); } } return(result); }