Zoom functionality in MediaPlayerElement: not getting manipulation events for scale gestures

karthik vr 31 Reputation points

I want to add zoom functionality for media player element(UWP C#) . I placed MediaPlayerElement inside a scroll viewer and zoom functionality is working. But inbuilt media transport transport controls is also getting zoomed and scrolled. To avoid this I tried implementing zoom through manipulation events as suggested in media player element doumentation https://learn.microsoft.com/en-gb/windows/uwp/audio-video-camera/play-audio-and-video-with-mediaplayer#pinch-and-zoom-video
I am not getting manipulation events for scale gestures((I tried mouse scroll, pinch gesture and stretch gesture in touch pad). But I am getting maniplation delta events for translate gestures.
Am I missing something. The code I tried is exactly same as said in the above link.
_mediaPlayerElement.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY;
_mediaPlayerElement.ManipulationDelta += _mediaPlayerElement_ManipulationDelta;

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,861 Reputation points

    Please check this paragraph from document

    allows you to specify the source rectangle within video content that should be rendered, effectively allowing you to zoom into video. The rectangle you specify is relative to a normalized rectangle (0,0,1,1) where 0,0 is the upper left hand of the frame and 1,1 specifies the full width and height of the frame. So, for example, to set the zoom rectangle so that the top-right quadrant of the video is rendered, you would specify the rectangle (.5,0,.5,.5). It is important that you check your values to make sure that your source rectangle is within the (0,0,1,1) normalized rectangle. Attempting to set a value outside of this range will cause an exception to be thrown.

    So please set the Rect smaller than 1 in the double tap event.

    private void _mediaPlayerElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)  
        _sourceRect = new Rect(0, 0, 0.5, 0.5);  
        _mediaPlayerElement.MediaPlayer.PlaybackSession.NormalizedSourceRect = _sourceRect;