Example #1
0
        public MainPage()
        {
            InitializeComponent();

            _compositor = Window.Current.Compositor;
            _tracker    = InteractionTracker.CreateWithOwner(_compositor, this);
            _progress   = _compositor.CreatePropertySet();

            RenderAdaptiveCard();

            RomeShare.SessionListUpdated += OnSessionListUpdated;
            Loaded += async(s, e) => await RomeShare.DiscoverSessionsAsync();

            // When the size of the app changes, we need to update all the measures.
            SizeChanged += (s, e) =>
            {
                if (_hitTestVisual != null)
                {
                    _hitTestVisual.Size = Card.RenderSize.ToVector2();

                    var distanceFromTop = (float)Card.RelativePosition(this).Y;
                    _maxDistance         = distanceFromTop + _hitTestVisual.Size.Y;
                    _tracker.MaxPosition = new Vector3(_maxDistance);

                    var trackerNode = _tracker.GetReference();
                    _progress.StartAnimation("Progress", trackerNode.Position.Y / _tracker.MaxPosition.Y);
                }
            };
        }
        public MainPage()
        {
            InitializeComponent();

            _compositor = Window.Current.Compositor;
            _progress   = _compositor.CreatePropertySet();

            RomeShare.MediaDataUpdated    += OnMediaDataUpdated;
            RomeShare.PositionDataUpdated += OnPositionDataUpdated;

            Loaded += async(s, e) => await RomeShare.CreateSessionAsync();
        }
Example #3
0
        private async void OnSessionListUpdated(object sender, EventArgs e)
        {
            if (RomeShare.AvailableSessions.FirstOrDefault() is RemoteSystemSessionInfo session)
            {
                await RomeShare.JoinSessionAsync(session);

                await DispatcherHelper.ExecuteOnUIThreadAsync(() => ConnectedText.Visibility = Visibility.Visible);
            }
            else
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() => ConnectedText.Visibility = Visibility.Collapsed);
            }
        }
Example #4
0
        public async void ValuesChanged(InteractionTracker sender, InteractionTrackerValuesChangedArgs args)
        {
            var dragPercent = args.Position.Y / _maxDistance;

            if (_idleStateEntered)
            {
                _idleStateEntered = false;
            }
            else
            {
                Debug.WriteLine(dragPercent);
                await RomeShare.SendPositionDataAsync(dragPercent);
            }
        }
Example #5
0
        private async void OnCardChromeHolding(object sender, HoldingRoutedEventArgs e)
        {
            if (e.PointerDeviceType == PointerDeviceType.Touch && e.HoldingState == HoldingState.Started)
            {
                // To create a continuous video playing experience, let's pause it here.
                _mediaElement.Pause();

                // Record the location as we want to resume from here on another device.
                _mediaPlayedPosition = _mediaElement.Position;

                // We don't want to visually move the video player. Instead, we want to create the illusion that
                // a "copy" of it is being dragged down to another device. So here we use RenderTargetBitmap to
                // create such visual.
                var bitmap = new RenderTargetBitmap();
                await bitmap.RenderAsync(Card);

                MediaCopy.Source = bitmap;

                MediaContainer.IsHitTestVisible = false;

                // Create animations to show that a "copy" of the video player is popped up and ready to be dragged up.
                Card.Fade(0.3f).Start();
                MediaCopy
                .Fade(0.7f, 1)
                .Then()
                .Scale(0.975f, 0.975f, (float)Card.ActualWidth / 2, (float)Card.ActualHeight / 2, 300d)
                .Then()
                .Offset(offsetY: -24.0f, duration: 400d)
                .Start();

                // Create an animation that changes the offset of the "copy" based on the manipulation progress.
                _mediaCopyVisual = VisualExtensions.GetVisual(MediaCopy);
                var progressExpressionNode = _progress.GetReference().GetScalarProperty("Progress");
                _mediaCopyVisual.StartAnimation("Offset.Y", progressExpressionNode * -_maxDistance);

                try
                {
                    // Let InteractionTracker to handle the swipe gesture.
                    _interactionSource.TryRedirectForManipulation(_pressedPoint);

                    // Send the card json and media played position over using Remote Sessions API.
                    await RomeShare.SendMediaDataAsync(_cardJson, _mediaPlayedPosition, MediaUrl);
                }
                catch (UnauthorizedAccessException) { }
            }
        }