Ejemplo n.º 1
0
        public VideoPlayer(VideoPlayerViewModel viewModel)
        {
            ViewModel   = viewModel;
            DataContext = viewModel;

            InitializeComponent();

            _streamWatchdogTimer.Interval = StreamWatchDogInterval;
            _streamWatchdogTimer.Tick    += (sender, args) =>
            {
                var mediaUri = ViewModel.MediaUri;
                if (mediaUri == null || _vlcControl.VlcMediaPlayer.IsPlaying())
                {
                    ViewModel.HasError = false;
                    return;
                }

                ViewModel.HasError = true;
                Console.WriteLine($"mediaPlayer {ViewModel.Index} is not playing stream {mediaUri}, attempting to restart it.");
                Play(mediaUri);
            };
            ViewModel.PropertyChanged += ViewModelOnPropertyChanged;

            _vlcControl           = new VlcControl();
            PlayerContainer.Child = _vlcControl;
            _vlcControl.BeginInit();
            _vlcControl.VlcLibDirectory = LibDirectory;
            _vlcControl.EndInit();

            _vlcControl.VlcMediaPlayer.Log += MediaPlayerOnLog;
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            for (var col = 0; col < NbColumns; col++)
            {
                PlayerGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (var row = 0; row < NbRows; row++)
            {
                PlayerGrid.RowDefinitions.Add(new RowDefinition());
            }

            var viewModels  = new List <VideoPlayerViewModel>();
            var playerIndex = 1;

            for (var row = 0; row < NbRows; row++)
            {
                for (var col = 0; col < NbColumns; col++)
                {
                    var viewModel = new VideoPlayerViewModel(playerIndex++);
                    viewModels.Add(viewModel);

                    var player = new VideoPlayer(viewModel);
                    PlayerGrid.Children.Add(player);
                    Grid.SetColumn(player, col);
                    Grid.SetRow(player, row);
                }
            }

            async Task AffectRandomStreams()
            {
                while (true)
                {
                    var viewModel = viewModels[Rnd.Next(viewModels.Count)];
                    var uri       = StreamUris[Rnd.Next(StreamUris.Count)];
                    await Dispatcher.InvokeAsync(() => viewModel.AffectMedia(uri));

                    await Task.Delay(Rnd.Next(10000));
                }
            }

            for (var i = 0; i < NbCallers; i++)
            {
                Task.Run(AffectRandomStreams);
            }
        }
        public VideoPlayer(VideoPlayerViewModel viewModel)
        {
            ViewModel   = viewModel;
            DataContext = viewModel;

            InitializeComponent();

            ViewModel.PropertyChanged += ViewModelOnPropertyChanged;

            _vlcControl           = new VlcControl();
            PlayerContainer.Child = _vlcControl;
            _vlcControl.BeginInit();
            _vlcControl.VlcLibDirectory = LibDirectory;
            _vlcControl.EndInit();

            _vlcControl.VlcMediaPlayer.Log += MediaPlayerOnLog;
        }