Does this violate MVVM principle? (MediaElementPlayer control)

I am developing xaml app with MediaPlayerElement and button that makes video jump 10 sec ahead.

  • I need to somehow touch the MediaPlayerElement to jump 10 seconds.
  • ViewModel shouldn’t care about view

So I came up with Interface that is implemented by View. Is works fine. But – Is there something wrong about this approach?

(sample code is intentionally simplified)


 <StackPanel> <MediaPlayerElement x:Name="Player" AreTransportControlsEnabled="True" Source="ms-appx:///Assets/vid.mp4" /> <Button Click="{x:Bind ViewModel.Jump10secAndNotify}" >Jump 10 sec</Button> </StackPanel> 


 public sealed partial class MainPage : Page,IMediaControl { public MainViewModel ViewModel { get; } = new MainViewModel(); public MainPage() { this.InitializeComponent(); ViewModel.MediaControl = this; } public void Jump10Seconds() => Player.MediaPlayer.PlaybackSession.Position += TimeSpan.FromSeconds(10); } 


 public IMediaControl MediaControl { get; set; } public void Jump10secAndNotify() { MediaControl.Jump10Seconds(); NotificationText = "I jumped 10 sec"; } 


 public interface IMediaControl { void Jump10Seconds(); } 

submitted by /u/venkuJeZima
[link] [comments]

Leave a Reply