Windows Phone 8 MediaStreamSource 具有多个音频流



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

  • 检测到 2 个流

  • 仅报告第一个或第二个媒体流音频流的说明到报告打开媒体已完成

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

开放媒体异步代码:

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

也许使用播放器框架是个好主意。它支持多种音频流。

相关内容

  • 没有找到相关文章

最新更新