如何解决UWP:后台任务中的音频媒体捕获
我是UWP的新手。我尝试通过MediaCapture API从后台线程录制音频。
我的代码在这里:
public sealed class Recorder : IBackgroundTask
{
private BackgroundTaskDeferral _deferral;
private readonly MediaCapture mediaCapture = new MediaCapture();
public async void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings()
{
StreamingCaptureMode = StreamingCaptureMode.Audio,};
await mediaCapture.InitializeAsync(settings);
var profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);
profile.Audio = AudioEncodingProperties.CreatePcm(16000,1,16);
await StartRecordAsync(profile);
_deferral.Complete();
}
private async Task StartRecordAsync(MediaEncodingProfile profile)
{
while(true)
{
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await storageFolder.CreateFileAsync(Guid.NewGuid() + ".wav",CreationCollisionOption.ReplaceExisting);
await mediaCapture.StartRecordToStorageFileAsync(profile,storageFile);
Task.Delay(10000).Wait();
await mediaCapture.StopRecordAsync();
}
}
}
它记录每个10秒钟的.wav文件,但是播放这些文件时,我什么也听不到。每个文件均为310KB +,因此不是0个字节。 有人知道为什么会发生吗?
解决方法
它记录每个10秒钟的.wav文件,但是当我播放这些文件时,我什么也听不到。每个文件均为310KB +,因此不是0个字节。有人知道为什么会发生吗?
恐怕您无法在<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:UP="urn:UP:Standard" exclude-result-prefixes="UP">
<xsl:output method="xml" indent="yes" />
<xsl:template match="UP:AuditFile">
<root>
<xsl:apply-templates select="UP:Header"/>
</root>
</xsl:template>
<xsl:template match="UP:Header">
<FileVersion>
<xsl:value-of select="UP:FileVersion" />
</FileVersion>
</xsl:template>
</xsl:stylesheet>
中捕获音频。来自官方document。
应从应用程序的主UI线程调用InitializeAsync。应用程序必须通过适当清理媒体捕获资源来处理应用程序暂停或终止。有关正确关闭MediaCapture对象的信息
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。