When I try to stream sound from my microphone, I need to get it through a MediaStreamSource.
Therefore I first need to implement a MediaStreamSource for the pcm waveformat I get from my Microphone. There are at least two methods I think I need to implement. At first
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);
}
This works very well. My CodecPrivateData is '01000100401F0000803E0000020010000000' (PCM 1ch 16Bits 8kHz). This method gets called by setting the source as here:
WaveMediaStreamSource WaveStream = new WaveMediaStreamSource(output);
mediaElement.SetSource(WaveStream);
mediaElement.Play();
After Play() absoultely nothing happens. I would suggest the mediaElement should call at least once the method GetSampleAsync() of the MediaStreamSource. But it doesn't. I've noticed that the MediaElement doesn't make any call to the MediaStreamSource anymore.
While OpenMediaAsync the mediaElement.CurrentState is Opening. After that it turns to Playing but it doesn't play. And then it do not change anymore and remains Playing.
Any Ideas?
To get to the bottom of this you need to check
MediaElement.CurrentState- it will tell you at which step of the interaction with theMediaStreamSourcetheMediaElementis stuck. This in turn will tell which of yourMediaStreamSourcemethods should be impemented differently...For a comprehensive walkthrough including essential information on the buffering part see http://msdn.microsoft.com/en-us/library/hh180779%28v=vs.95%29.aspx