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.
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