MainPage.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Animation;
  13. using System.Windows.Shapes;
  14. using MatrixIO.IO.MpegTs;
  15. using MatrixIO.IO.MpegTs.Streams;
  16. namespace SLTest
  17. {
  18. public partial class MainPage : UserControl
  19. {
  20. public ObservableCollection<TsUdpMediaStreamSource> Sources { get; private set; }
  21. public MainPage()
  22. {
  23. Debug.WriteLine("Loading...");
  24. new MpegTsPortabilityFactory();
  25. Sources = new ObservableCollection<TsUdpMediaStreamSource>();
  26. InitializeComponent();
  27. Loaded += OnLoaded;
  28. }
  29. void OnLoaded(object sender, RoutedEventArgs e)
  30. {
  31. if (App.Current.HasElevatedPermissions)
  32. Sources.Add(new TsUdpMediaStreamSource(new Uri("udp://224.0.0.42:4242/")));
  33. else
  34. Debug.WriteLine("This application requires elevated permissions to run.");
  35. }
  36. private void SourceTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  37. {
  38. var stream = e.NewValue as TsStream;
  39. if (stream != null)
  40. {
  41. MessageBox.Show("New selected stream is " + stream.Type + " with " + stream.Info.Count + " descriptors.");
  42. var streamSource = new TestStreamSource(stream);
  43. mediaElement.SetSource(streamSource);
  44. }
  45. }
  46. private void mediaElement_MediaFailed(object sender, ExceptionRoutedEventArgs e)
  47. {
  48. MessageBox.Show(e.ErrorException.ToString());
  49. }
  50. private void mediaElement_BufferingProgressChanged(object sender, RoutedEventArgs e)
  51. {
  52. Dispatcher.BeginInvoke(() => bufferingProgress.Value = ((MediaElement) e.OriginalSource).BufferingProgress);
  53. }
  54. }
  55. }