public async Task StartAsync(Uri source, CancellationToken cancellationToken)
        {
            // ReSharper disable once PossiblyMistakenUseOfParamsMethod
            _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            _mediaStreamFacade = new MediaStreamFacade();

            var builder = _mediaStreamFacade.Builder as BuilderBase;

            if (null == builder)
                throw new Exception("Unsupported builder type");

            var containerBuilder = builder.ContainerBuilder;

            containerBuilder.RegisterType<SingleStreamMediaManager>().As<IMediaManager>().InstancePerMatchingLifetimeScope("builder-scope");

            var mediaElementManager = new SimulatedMediaElementManager();

            _mediaStreamFacade.SetParameter(new SimulatedMediaStreamConfigurator(mediaElementManager));

            var mss = await _mediaStreamFacade.CreateMediaStreamSourceAsync(source, _cancellationTokenSource.Token).ConfigureAwait(false);

            if (null == mss)
            {
                Debug.WriteLine("Unable to create media stream source");
                return;
            }

            mediaElementManager.SetSource(mss);

            mediaElementManager.Play();
        }
Beispiel #2
0
        public async Task StartAsync()
        {
            var mediaElementManager = new SimulatedMediaElementManager();

            _mediaStreamFacade = new MediaStreamFacade();

            _mediaStreamFacade.SetParameter(_httpClientFactoryParameters);

            _mediaStreamFacade.SetParameter(new SimulatedMediaStreamConfigurator(mediaElementManager));

            var source = new Uri(Sources[0]);

            var mss = await _mediaStreamFacade.CreateMediaStreamSourceAsync(source, CancellationToken.None).ConfigureAwait(false);

            if (null == mss)
            {
                Debug.WriteLine("Unable to create media stream source");
                return;
            }

            mediaElementManager.SetSource(mss);

            Thread.Sleep(750);

            mediaElementManager.Play();

            return;
#pragma warning disable 162
            var timer = new Timer(_ =>
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();

                var gcMemory = GC.GetTotalMemory(true).BytesToMiB();

                var source2 = Sources[_count];

                Debug.WriteLine("Switching to {0} (GC {1:F3} MiB)", source, gcMemory);

                var url = null == source ? null : new Uri(source2);

                if (++_count >= Sources.Length)
                    _count = 0;
            });

            timer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
#pragma warning restore 162
        }