private void Player_DataReceived(object sender, DataReceivedInfo e) { if (IsCaptionStream(e.StreamAttributes)) { try { var stream = new MemoryStream(e.Data); var text = new StreamReader(stream).ReadToEnd(); var duration = e.DataChunk.Duration != TimeSpan.Zero ? e.DataChunk.Duration : TimeSpan.FromMilliseconds(2002); if (_captionRegion.Begin == TimeSpan.MinValue || _captionRegion.Begin > e.DataChunk.Timestamp) { _captionRegion.Begin = e.DataChunk.Timestamp; } #if SILVERLIGHT3 if (!SystemExtensions.IsNullOrWhiteSpace(text)) #else if (!string.IsNullOrWhiteSpace(text)) #endif { var caption = new CaptionElement { Content = text, Begin = e.DataChunk.Timestamp, End = e.DataChunk.Timestamp.Add(duration) }; _captionRegion.Children.Add(caption); } } catch (Exception err) { Debug.WriteLine(err.Message); } } }