当我尝试从麦克风传输声音时,我需要通过MediaStreamSource
. 因此,我首先需要为MediaStreamSource
从麦克风获得的 pcm 波形实现一个。我认为至少有两种方法需要实现。首先
protected override void OpenMediaAsync() {
// Create description
Dictionary<MediaStreamAttributeKeys, string> streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
streamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = output.CodecPrivateData;
audioDesc = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes);
// register stream
Dictionary<MediaSourceAttributesKeys, string> sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
List<MediaStreamDescription> availableStreams = new List<MediaStreamDescription>();
availableStreams.Add(audioDesc);
sourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromMinutes(0).Ticks.ToString(); // whatever I put here I get the same result.
sourceAttributes[MediaSourceAttributesKeys.CanSeek] = false.ToString();
ReportOpenMediaCompleted(sourceAttributes, availableStreams);
}
这很好用。我的 CodecPrivateData 是“01000100401F0000803E0000020010000000”(PCM 1ch 16Bits 8kHz)。通过将源设置为此处调用此方法:
WaveMediaStreamSource WaveStream = new WaveMediaStreamSource(output);
mediaElement.SetSource(WaveStream);
mediaElement.Play();
之后Play()
绝对没有任何反应。我建议mediaElement应该至少调用一次GetSampleAsync()
. MediaStreamSource
但事实并非如此。我注意到不再MediaElement
对 the 进行任何调用MediaStreamSource
。
虽然是. OpenMediaAsync
_ 之后它会变成但它不播放。然后它不再改变并保持不变。mediaElement.CurrentState
Opening
Playing
Playing
有任何想法吗?