当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Windows Phone 8 MediaStreamSource with multiple audio streams

问题描述:

I have MediaStreamSource implementation which can open files with multiple audio streams. In OpenMediaAsync method i deliver MediaStreamDescription for all video and audio streams but MediaElement detects only 1 audio stream. Also I have tested next logic which works:

  • detected 2 streams

  • report only first or second MediaStreamDescription of audio stream to ReportOpenMediaCompleted

But of course I want to report first and second audio stream to ReportOpenMediaCompleted and in result have MediaElement with 2 audio streams. Also I have discovered StreamId field inside MediaStreamSource class but it doesn't have set accessor, and when reporting streams with ReportOpenMediaCompleted all MediaStreamDescription have StreamId == 0.

OpenMediaAsync code:

protected override void OpenMediaAsync()

{

this.streamDesc = new Dictionary<int, MediaStreamDescription>();

List<MediaStreamDescription> availableStreams = new List<MediaStreamDescription>();

for (int i = 0; i < this.parser.StreamCount; i++)

{

Dictionary<MediaStreamAttributeKeys, string> streamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();

MediaStreamDescription msd = null;

var type = this.parser.GetStreamType(i);

streamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = this.parser.GetCodecPrivateData(i);

if (type == ParserComponent.StreamType.Video)

{

streamAttributes[MediaStreamAttributeKeys.VideoFourCC] = this.parser.GetCodecID(i);

streamAttributes[MediaStreamAttributeKeys.Width] = this.parser.GetWidth(i).ToString();

streamAttributes[MediaStreamAttributeKeys.Height] = this.parser.GetHeight(i).ToString();

msd = new MediaStreamDescription(MediaStreamType.Video, streamAttributes);

}

else if (type == ParserComponent.StreamType.Audio)

{

msd = new MediaStreamDescription(MediaStreamType.Audio, streamAttributes);

}

if (msd != null)

{

if (i == this.parser.CurrentAudioStreamIndex || i == this.parser.CurrentVideoStreamIndex)

{

this.parser.SetStreamActive(i, true);

// quick fix for multilanguage videos to submit only 1 audio stream

// availableStreams.Add(msd);

}

this.streamDesc.Add(i, msd);

availableStreams.Add(msd);

}

}

Dictionary<MediaSourceAttributesKeys, string> sourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();

sourceAttributes[MediaSourceAttributesKeys.CanSeek] = this.parser.Seekable.ToString();

sourceAttributes[MediaSourceAttributesKeys.Duration] = this.parser.Duration.Ticks.ToString();

ReportOpenMediaCompleted(sourceAttributes, availableStreams);

}

网友答案:

May be it's a good idea to use Player framework. It supports multiple audio streaming.

分享给朋友:
您可能感兴趣的文章:
随机阅读: