0

我有 MediaStreamSource 实现,它可以打开具有多个音频流的文件。在 OpenMediaAsync 方法中,我为所有视频和音频流提供 MediaStreamDescription,但 MediaElement 仅检测到 1 个音频流。我还测试了下一个有效的逻辑:

  • 检测到 2 个流

  • 仅向 ReportOpenMediaCompleted 报告音频流的第一个或第二个 MediaStreamDescription

但是我当然想向 ReportOpenMediaCompleted 报告第一个和第二个音频流,结果是 MediaElement 有 2 个音频流。我还在 MediaStreamSource 类中发现了 StreamId 字段,但它没有设置访问器,并且当使用 ReportOpenMediaCompleted 报告流时,所有 MediaStreamDescription 的 StreamId == 0。

OpenMediaAsync 代码:

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);
}
4

1 回答 1

0

使用Player 框架可能是个好主意。它支持多个音频流。

于 2014-04-07T13:21:37.890 回答