src/FingersDance.Control.Player/UserControlPlayer.xaml.cs
author sarias
Sun, 11 Oct 2009 20:38:22 +0200
changeset 139 7eb5f979d086
parent 136 8b513df1b446
child 146 dd8ed4d3beb6
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     1
using System;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     2
using System.IO;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     3
using System.Net;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     4
using System.Windows;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     5
using System.Windows.Controls;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     6
using System.Windows.Data;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     7
using System.Windows.Media;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     8
using System.Windows.Media.Imaging;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
     9
using System.Windows.Media.Animation;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    10
using System.Windows.Navigation;
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    11
using System.ComponentModel;
49
b23aa9d09ac1 debug for video path
cavaliet
parents: 41
diff changeset
    12
using System.Reflection;
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
    13
using System.Collections.Generic;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    14
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
    15
using Microsoft.Surface.Presentation;
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
    16
using Microsoft.Surface.Presentation.Controls;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
    17
using FingersDance.ActionFactory;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
    18
using FingersDance.Actions;
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
    19
using FingersDance.Control.TimeLine;
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
    20
using FingersDance.Views;
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
    21
using FingersDance.ViewModels;
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
    22
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    23
namespace FingersDance.Control.Player
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    24
{
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    25
	public partial class UserControlPlayer
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    26
	{
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    27
        #region Variables
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    28
        private bool isPlaying = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    29
        #endregion
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    30
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    31
        public event EventHandler PlayerOpened;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    32
119
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    33
        public UserControlPlayer()
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    34
        {
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    35
            this.InitializeComponent();
121
32611257e99f Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 119
diff changeset
    36
            MediaElementVideo.LoadedBehavior = MediaState.Manual;
32611257e99f Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 119
diff changeset
    37
            MediaElementVideo.UnloadedBehavior = MediaState.Manual;
119
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    38
        }
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    39
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    40
        #region Properties
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    41
        public double TotalMilliseconds
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    42
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    43
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    44
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    45
                return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    46
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    47
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    48
        public MediaElement Player
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    49
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    50
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    51
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    52
                return MediaElementVideo;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    53
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    54
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    55
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    56
                MediaElementVideo= value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    57
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    58
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    59
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    60
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    61
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    62
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    63
        #region Methodes
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    64
119
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    65
        public void initPlayer(string path)
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    66
        {
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    67
            //init player
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    68
            isPlaying = false;
121
32611257e99f Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 119
diff changeset
    69
            MediaElementVideo.Source = new Uri(path);
119
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    70
            MediaElementVideo.ScrubbingEnabled = true;
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    71
        }
PAMPHILE Jonathan <pamphile@efrei.fr>
parents: 77
diff changeset
    72
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    73
        public void playerPause()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    74
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    75
            MediaElementVideo.Pause();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    76
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    77
        public void playerPlay()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    78
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    79
            MediaElementVideo.Play();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    80
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    81
        public void playerStop()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    82
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    83
            MediaElementVideo.Stop();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    84
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    85
        
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    86
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    87
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    88
        private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    89
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    90
            if (!isPlaying)//Play
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    91
            {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    92
                isPlaying = true;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    93
                try
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    94
                {
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    95
                    MediaElementVideo.Play();
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    96
                }
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    97
                catch (Exception ex) { }
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    98
            }
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
    99
            else//Pause
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   100
            {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   101
                isPlaying = false;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   102
                try
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   103
                {
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   104
                    MediaElementVideo.Pause();
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   105
                }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   106
                catch (Exception exx) { }
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   107
            }
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   108
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   109
        }
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   110
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   111
        private void ButtonPlayPause_Click(object sender, RoutedEventArgs e)
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   112
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   113
            if (!isPlaying)//Play
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   114
            {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   115
                isPlaying = true;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   116
                try
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   117
                {
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   118
                    MediaElementVideo.Play();
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   119
                }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   120
                catch (Exception ex) { }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   121
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   122
            }
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   123
            else//Pause
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   124
            {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   125
                isPlaying = false;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   126
                try
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   127
                {
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   128
                    MediaElementVideo.Pause();
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   129
                }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   130
                catch (Exception exx) { }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   131
                //ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   132
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   133
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   134
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   135
        private void ButtonFastForward_Click(object sender, RoutedEventArgs e)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   136
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   137
            if (MediaElementVideo.SpeedRatio <= 3)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   138
                MediaElementVideo.SpeedRatio += 1;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   139
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   140
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   141
        private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   142
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   143
            if (MediaElementVideo.SpeedRatio <= 3)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   144
                MediaElementVideo.SpeedRatio += 1;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   145
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   146
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   147
        private void ButtonRewind_Click(object sender, RoutedEventArgs e)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   148
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   149
            //TimeSpan ts = new TimeSpan(0, 0, 0, 0);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   150
            if (MediaElementVideo.SpeedRatio > 1)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   151
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   152
                MediaElementVideo.SpeedRatio -= 1;
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   153
            }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   154
            else
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   155
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   156
                MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5));
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   157
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   158
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   159
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   160
        private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   161
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   162
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   163
            //TimeSpan ts = new TimeSpan(0, 0, 0,0);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   164
            if (MediaElementVideo.SpeedRatio > 1)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   165
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   166
                MediaElementVideo.SpeedRatio -= 1;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   167
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   168
            else
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   169
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   170
                MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5));
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   171
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   172
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   173
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   174
        private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   175
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   176
            OnPlayerOpened();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   177
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   178
        protected virtual void OnPlayerOpened()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   179
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   180
            if(PlayerOpened!=null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   181
                PlayerOpened(this, new EventArgs());
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   182
        }
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   183
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   184
        private void Play_Pause_area_DragEnter(object sender, SurfaceDragDropEventArgs e)
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   185
        {
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   186
            //Console.WriteLine("Enter");
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   187
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   188
            // If the TimelineAnnotationView comes from a user control different from the current one, 
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   189
            // it means that we want to add the annotation to the current list.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   190
            // So we check if the dragged annotation can be dragged or if it will recover any existant annotation (in this case it will not be accepted)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   191
            // e.Cursor.DragSource is the SurfaceListBox where the drag started from
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   192
            SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   193
            // We get the instance of the UserControlSyncSource
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   194
            UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   195
            // and its UserControlTimeline
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   196
            UserControlTimeLine tl = (UserControlTimeLine)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0];
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   197
            if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   198
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   199
                // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   200
                AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   201
                Play_Pause_area.Background = tl.isAnnotationAccepted(annotationDataVM) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   202
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   203
            else
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   204
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   205
                Play_Pause_area.Background = new SolidColorBrush(Colors.White);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   206
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   207
            Play_Pause_area.Opacity = 0.3;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   208
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   209
        }
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   210
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   211
        private void Play_Pause_area_DragLeave(object sender, SurfaceDragDropEventArgs e)
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   212
        {
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   213
            //Console.WriteLine("Leave");
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   214
            Play_Pause_area.Opacity = 0;
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   215
        }
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   216
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   217
        private void Play_Pause_area_DragOver(object sender, SurfaceDragDropEventArgs e)
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   218
        {
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   219
            //Console.WriteLine("Over");
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   220
        }
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   221
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   222
        private void Play_Pause_area_Drop(object sender, SurfaceDragDropEventArgs e)
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   223
        {
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   224
            //Console.WriteLine("Drop");
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   225
            Play_Pause_area.Opacity = 0;
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   226
            // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   227
            AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   228
            int nbSeconds = (int)annotationDataVM.TcBegin;
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   229
            int nbMilliSec = (int)((annotationDataVM.TcBegin * 1000)%1000);
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   230
            MediaElementVideo.Position = new TimeSpan(0, 0, 0, nbSeconds, nbMilliSec);
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   231
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   232
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   233
            // If the TimelineAnnotationView comes from a user control different from the current one, 
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   234
            // it means that we want to add the annotation to the current list.
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   235
            // So we generate the ActionAddAnnotation
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   236
            // e.Cursor.DragSource is the SurfaceListBox where the drag started from
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   237
            SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   238
            // We get the instance of the UserControlSyncSource
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   239
            UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   240
            // and its UserControlTimeline
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   241
            UserControl tl = (UserControl)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0];
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   242
            if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   243
            {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   244
                // Now we build the action arguments : a list holding the timeline and the annotation view models
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   245
                List<Object> actionsArgs = new List<Object>();
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   246
                actionsArgs.Add(tl);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   247
                actionsArgs.Add(annotationDataVM);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   248
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   249
                ActionGenerator ag = new ActionGenerator();
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   250
                ActionBase ab = ag.GetAction("ActionAddAnnotation", actionsArgs);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   251
                if (ab != null)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   252
                    ab.Execute();
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   253
            }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 134
diff changeset
   254
134
f5108a598aa7 drag and drop places the video at the good timecode.
cavaliet
parents: 122
diff changeset
   255
        }
3
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   256
	}
4f1ea403073d Projet Menu avec profondeur complete.
sarias
parents:
diff changeset
   257
}