/// <summary> /// カバーアート画像を追加する。 /// </summary> /// <returns>true: カバーアート画像が付いている。false: カバーアート画像がついていない。</returns> private bool AddCoverart(string path, PcmDataLib.PcmData pcmData) { if (0 < pcmData.PictureBytes) { // 既に追加されている。 return(true); } try { var dirPath = System.IO.Path.GetDirectoryName(path); var pictureData = ReadWholeFile(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}.jpg", dirPath, System.IO.Path.GetFileNameWithoutExtension(path))); if (0 < pictureData.Length) { // ファイル名.jpgが存在。 pcmData.SetPicture(pictureData.Length, pictureData); return(true); } foreach (string albumImageFilename in ALBUM_IMAGE_FILENAMES) { pictureData = ReadWholeFile(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", dirPath, albumImageFilename)); if (0 < pictureData.Length) { // アルバムのカバーアート画像(folder.jpg等)が存在。 pcmData.SetPicture(pictureData.Length, pictureData); return(true); } } } catch (Exception ex) { // エラーが起きたら読まない。 LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, "W: coverart image read failed: {0}", ex)); } return(false); }
/// <summary> /// WAVファイルのヘッダ部分を読み込む。 /// </summary> /// <returns>読めたらtrue</returns> private bool ReadWavFileHeader(string path) { bool result = false; var pd = new PcmDataLib.PcmData(); var wavR = new WavReader(); using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { if (wavR.ReadHeader(br)) { // WAVヘッダ読み込み成功。PcmDataを作って再生リストに足す。 pd.SetFormat(wavR.NumChannels, wavR.BitsPerSample, wavR.ValidBitsPerSample, (int)wavR.SampleRate, wavR.SampleValueRepresentationType, wavR.NumFrames); if ("RIFFINFO_INAM".Equals(wavR.Title) && "RIFFINFO_IART".Equals(wavR.ArtistName)) { // Issue 79 workaround } else { if (wavR.Title != null) { pd.DisplayName = wavR.Title; } if (wavR.AlbumName != null) { pd.AlbumTitle = wavR.AlbumName; } if (wavR.ArtistName != null) { pd.ArtistName = wavR.ArtistName; } } pd.SetPicture(wavR.PictureBytes, wavR.PictureData); result = CheckAddPcmData(path, pd, true); } else { LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ReadFileFailed + ": {1} : {2}{3}", "WAV", path, wavR.ErrorReason, Environment.NewLine)); } } return(result); }
private bool ReadMp3FileHeader(string path) { bool result = false; var pd = new PcmDataLib.PcmData(); WWMFReader.Metadata meta; int rv = WWMFReader.ReadHeader(path, out meta); if (0 <= rv) { pd.SetFormat(meta.numChannels, meta.bitsPerSample, meta.bitsPerSample, meta.sampleRate, PcmData.ValueRepresentationType.SInt, meta.numApproxFrames); pd.SampleDataType = PcmDataLib.PcmData.DataType.PCM; pd.DisplayName = meta.title; pd.AlbumTitle = meta.album; pd.ArtistName = meta.artist; pd.ComposerName = meta.composer; if (null != meta.picture) { pd.SetPicture(meta.picture.Length, meta.picture); } pd.BitRate = meta.bitRate; pd.IsLossyCompressed = true; if (CheckAddPcmData(path, pd, true)) { result = true; } } else { LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ReadFileFailed + " {1}: {2}{3}", "MP3", rv, path, Environment.NewLine)); } return(result); }
/// <summary> /// WAVファイルのヘッダ部分を読み込む。 /// </summary> /// <returns>読めたらtrue</returns> private bool ReadWavFileHeader(string path) { bool result = false; var pd = new PcmDataLib.PcmData(); var wavR = new WavReader(); using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { if (wavR.ReadHeader(br)) { // WAVヘッダ読み込み成功。PcmDataを作って再生リストに足す。 pd.SetFormat(wavR.NumChannels, wavR.BitsPerSample, wavR.ValidBitsPerSample, (int)wavR.SampleRate, wavR.SampleValueRepresentationType, wavR.NumFrames); if ("RIFFINFO_INAM".Equals(wavR.Title) && "RIFFINFO_IART".Equals(wavR.ArtistName)) { // Issue 79 workaround } else { if (wavR.Title != null) { pd.DisplayName = wavR.Title; } if (wavR.AlbumName != null) { pd.AlbumTitle = wavR.AlbumName; } if (wavR.ArtistName != null) { pd.ArtistName = wavR.ArtistName; } } pd.SetPicture(wavR.PictureBytes, wavR.PictureData); result = CheckAddPcmData(path, pd, true); } else { LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ReadFileFailed + ": {1} : {2}{3}", "WAV", path, wavR.ErrorReason, Environment.NewLine)); } } return result; }