PlayerControl.xaml.cs 942 Bytes
Newer Older
Martin Finkel's avatar
Martin Finkel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
using Xamarin.Forms;

namespace Gestures
{
    public partial class PlayerControl : ContentPage
    {
        MainViewModel _vm;

        public PlayerControl()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

18
            videoView.MediaPlayerChanged += MediaPlayerChanged;
Martin Finkel's avatar
Martin Finkel committed
19 20 21 22 23 24 25 26 27

            _vm = BindingContext as MainViewModel;
            _vm.Initialize();
        }

        protected override void OnDisappearing()
        {
            base.OnDisappearing();

28
            videoView.MediaPlayerChanged -= MediaPlayerChanged;
Martin Finkel's avatar
Martin Finkel committed
29 30 31 32 33

            _vm = BindingContext as MainViewModel;
            _vm.Stop();
        }

34
        private void MediaPlayerChanged(object sender, System.EventArgs e)
Martin Finkel's avatar
Martin Finkel committed
35 36 37 38 39 40 41
        {
            _vm.MediaPlayer.Play();
        }
        
        void PanUpdated(object sender, PanUpdatedEventArgs e) => _vm.OnGesture(e);
    }
}