IIS Smooth streaming low quality on start

前端 未结 4 1458
温柔的废话
温柔的废话 2020-12-31 21:26

I m hosting some adaptive streaming video on windows azure and I have noticed that at the beginning the video start with the lowest avaiable bitrate. That is a big issue.

4条回答
  •  無奈伤痛
    2020-12-31 21:45

    Hello I posted the question to the Media Platform Player forum and got an answer that works.

    The discussion is here: http://smf.codeplex.com/discussions/271042

    Here is the code I use:

    public MainPage() {
            InitializeComponent();
            player.MediaPluginRegistered += new EventHandler>(player_MediaPluginRegistered);
            player.PlayStateChanged += new EventHandler>(Player_PlayStateChanged);
        }
    private IAdaptiveMediaPlugin _adaptivePlugin = null;
    private bool isStartupHeuristicsActive = false;
    
    void player_MediaPluginRegistered(object sender, CustomEventArgs e) {
        var adaptivePlugin = e.Value as IAdaptiveMediaPlugin;
        if (adaptivePlugin == null) return; 
        if (_adaptivePlugin == null) _adaptivePlugin = adaptivePlugin;
        _adaptivePlugin.ManifestReady +=new Action(_adaptivePlugin_ManifestReady);
    }
    
    void  _adaptivePlugin_ManifestReady(IAdaptiveMediaPlugin obj)
    {
        if (_adaptivePlugin != null)
        {
            var videoStream = _adaptivePlugin.CurrentSegment.SelectedStreams.Where(i => i.Type == StreamType.Video).FirstOrDefault();
    
            if (videoStream != null)
            {
                var averageBitrate = videoStream.AvailableTracks.Average(t => t.Bitrate);
    
                var track = videoStream.AvailableTracks.FirstOrDefault(t => t.Bitrate >= averageBitrate);
                if (track != null)
                {
                    isStartupHeuristicsActive = true;
                    videoStream.SetSelectedTracks(new[] { track });
                }
            }
        }
    }
    
    private void Player_PlayStateChanged(object sender, CustomEventArgs e)
    {
        if (isStartupHeuristicsActive && e.Value == MediaPluginState.Playing)
        {
            isStartupHeuristicsActive = false;
            if (_adaptivePlugin != null)
            {
                var videoStream = _adaptivePlugin.CurrentSegment.SelectedStreams.Where(i => i.Type == StreamType.Video).FirstOrDefault();
                if (videoStream != null)
                {
                    videoStream.SetSelectedTracks(videoStream.AvailableTracks);
                }
            }
        }
    }
    

    Thank you

提交回复
热议问题