xref: /MusicPlayer2/MusicPlayer2/AudioTag.h (revision 9b32c1f65086ce3ea42d441b2f3350b622a575e7)
1 #pragma once
2 #include "AudioCommon.h"
3 
4 class CAudioTag
5 {
6 public:
7     CAudioTag(SongInfo& song_info, HSTREAM hStream = 0);       //获取的标签信息保存在song_info中,hStream用来判断音频类型,非必须
8     CAudioTag(SongInfo& song_info, AudioType type);
9     CAudioTag(const wstring& file_path);
10     ~CAudioTag();
11 
12     //获取音频文件的标签信息,结果保存在构造函数传递进来的SongInfo结构里,
13     bool GetAudioTag();
14 
15     void GetAudioTagPropertyMap(std::map<wstring, wstring>& property_map);
16 
17     //获取音频文件的专辑封面,并保存到临时目录
18     //image_type:用来接收封面的格式 0:jpg, 1:png, 2:gif
19     //file_name: 指定保存的专辑封面的文件名,如果为nullptr,则使用默认的文件名
20     //file_size: 用来接收获取到的专辑封面文件大小
21     //返回值:专辑封面的保存路径
22     wstring GetAlbumCover(int& image_type, const wchar_t* file_name = nullptr, size_t* file_size = nullptr);
23 
24     //获取音频的内嵌歌词
25     wstring GetAudioLyric();
26 
27     bool WriteAudioLyric(const wstring& lyric_contents);
28 
GetAudioType()29     AudioType GetAudioType() const { return m_type; }
30 
31     //写入一个标签信息
32     bool WriteAudioTag();
33 
34     //写入一个专辑封面
35     bool WriteAlbumCover(const wstring& album_cover_path);
36 
37     //获取音频内嵌cue
38     wstring GetAudioCue();
39 
40     //获取歌曲分级,保存到构造函数传递进来的SongInfo结构中
41     void GetAudioRating();
42 
43     //写入歌曲分级,将构造函数传递进来的SongInfo结构中的分级保存到文件
44     bool WriteAudioRating();
45 
46     //根据一个文件扩展名判断此格式是否已支持写入标签
47     static bool IsFileTypeTagWriteSupport(const wstring& ext);
48 
49     //根据一个文件扩展名判断此格式是否已支持写入标签
50     static bool IsFileTypeCoverWriteSupport(const wstring& ext);
51 
52     static bool IsFileTypeLyricWriteSupport(const wstring& ext);
53 
54     //根据一个文件扩展名判断此格式是否支持分级
55     static bool IsFileRatingSupport(const wstring& ext);
56 
57 protected:
58     //获取cue文件的路径
59     static std::wstring GetCuePath(SongInfo& song_info);
60 
61     //从cue文件中获取一个cue音轨中的信息
62     static bool GetCueTag(SongInfo& song_info);
63 
64     //将一个cue音轨的信息写入cue文件
65     static bool WriteCueTag(SongInfo& song_info);
66 
67     //读取一个cue音轨的所有标签属性
68     static bool GetCuePropertyMap(SongInfo& song_info, std::map<wstring, wstring>& property_map);
69 
70 private:
71     SongInfo& m_song_info;
72     HSTREAM m_hStream{};
73     AudioType m_type;
74     SongInfo m_no_use;
75 };
76