我正在尝试制作一个工具,通过这个规范来编辑和嵌入mp3文件中的章节标记(用于播客)。到目前为止,我找到的所有库都不支持CHAP或CTOC帧,也找不到一种方法使它们与自定义帧一起使用。目前我最喜欢的是NTagLite,但我在VS2017上构建源代码时遇到了麻烦,因为我不是非常高级的程序员,所以手动使用ByteStream有些困难。有没有人知道如何实现这个功能?有没有经验的人可以提供帮助?是否只是我错过了这些库中的调用,而该功能已经存在了?
using System;
using ATL.AudioData;
using System.Collections.Generic;
AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(<fileLocation>));
Dictionary<uint, ChapterInfo> expectedChaps = new Dictionary<uint, ChapterInfo>();
TagData theTag = new TagData();
theTag.Chapters = new List<ChapterInfo>();
expectedChaps.Clear();
ChapterInfo ch = new ChapterInfo();
ch.StartTime = 123;
ch.StartOffset = 456;
ch.EndTime = 789;
ch.EndOffset = 101112;
ch.UniqueID = "";
ch.Title = "aaa";
ch.Subtitle = "bbb";
ch.Url = "ccc\0ddd";
theTag.Chapters.Add(ch);
expectedChaps.Add(ch.StartTime, ch);
ch = new ChapterInfo();
ch.StartTime = 1230;
ch.StartOffset = 4560;
ch.EndTime = 7890;
ch.EndOffset = 1011120;
ch.UniqueID = "002";
ch.Title = "aaa0";
ch.Subtitle = "bbb0";
ch.Url = "ccc\0ddd0";
theTag.Chapters.Add(ch);
expectedChaps.Add(ch.StartTime, ch);
// Persists the chapters
theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_ID3V2);
// Reads them
theFile.ReadFromFile(null, true);
foreach (ChapterInfo chap in theFile.ID3v2.Chapters)
{
System.Console.WriteLine(chap.Title + "(" + chap.StartTime + ")");
}
public class ChapterFrame : Frame
{
private Header Header { get; set; }
private string ElementId { get; set; }
private TimeSpan StartTime { get; set; }
private TimeSpan EndTime { get; set; }
private TimeSpan StartOffset { get; set; }
private TimeSpan EndOffset { get; set; }
private List<ChapterFrame> Subframes = new List<ChapterFrame>();
}
然后编写一些方法(类似于ChapterFrame.ToByteArray()
):
public byte[] ToByteArray(ChapterFrame frame) {
return new byte[];
}
这段代码将每个 ChapterFrame
的字段提取出来,将它们展开成符合 ID3 v2.3/2.4 章节帧补充标准的序列化字节数组:
现在你已经有了一个新的框架,你可以扫描ID3标签来确定在哪里插入新的框架。
请注意,我绝对不是专家 - 这只是一个猜测。