如何将两个音频文件(.mp3,.aac)合并到Metro中的单个音频文件中?有可能吗?
答案 0 :(得分:0)
不了解音频文件, 但试着这个组合文件:
public static async Task<StorageFile> CombineFiles(string[] files, string filepath)
{
StorageFile sf;
byte[] b;
byte[] allfiles = new byte[0];
int position = 0;
for (int i = 0; i < files.Length; i++)
{
sf = await StorageFile.GetFileFromPathAsync(files[i]);
b = await Conversions.Convert_StorageFileToByteArray_Async(sf);
Array.Resize(ref allfiles, allfiles.Length + b.Length);
Array.Copy(b, 0, allfiles, position, b.Length);
position += b.Length;
}
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
StorageFolder tempfolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
sf = await Conversions.Convert_ByteArrayToStorageFile(allfiles, tempfolder, filename);
return sf;
}
//convert byte array to a storageFile
public static async Task<StorageFile> Convert_ByteArrayToStorageFile(Byte[] data_byte, StorageFolder folder, string fileName)
{
StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0))
{
using (DataWriter dataWriter = new DataWriter(outputStream))
{
dataWriter.WriteBytes(data_byte);
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
//write data on the empty file:
await outputStream.FlushAsync();
}
//write data on the empty file:
await fileStream.FlushAsync();
return file;
}
}