| author | totetm <> |
| Thu, 04 Feb 2010 16:38:04 +0100 | |
| changeset 38 | bd33267300aa |
| parent 36 | b6df6fce6e5d |
| permissions | -rw-r--r-- |
| 0 | 1 |
using System; |
2 |
using System.Windows; |
|
3 |
using System.Windows.Controls; |
|
4 |
using System.Windows.Documents; |
|
5 |
using System.Windows.Ink; |
|
6 |
using System.Windows.Input; |
|
7 |
using System.Windows.Media; |
|
8 |
using System.Windows.Media.Animation; |
|
9 |
using System.Windows.Shapes; |
|
10 |
using Iri.Modernisation.BaseMVVM.Commands; |
|
11 |
using Iri.Modernisation.Controls.ViewModel; |
|
12 |
namespace Iri.Modernisation.Controls.View |
|
13 |
{ |
|
14 |
public partial class VideoViewer : UserControl |
|
15 |
{ |
|
16 |
||
17 |
||
| 22 | 18 |
|
19 |
public System.Windows.Threading.DispatcherTimer VideoPositionTimer = new System.Windows.Threading.DispatcherTimer(); |
|
20 |
|
|
| 0 | 21 |
public String MediaSource |
22 |
{ |
|
23 |
get |
|
24 |
{ |
|
| 29 | 25 |
|
| 0 | 26 |
return (String)GetValue(SourceProperty); |
27 |
} |
|
28 |
set |
|
29 |
{ |
|
30 |
SetValue(SourceProperty, value); |
|
31 |
if(DataContext != null) |
|
32 |
((VideoViewerVM)DataContext).Source = value; |
|
33 |
} |
|
34 |
} |
|
35 |
||
36 |
// Using a DependencyProperty as the backing store for Source. This enables animation, styling, binding, etc... |
|
37 |
public static readonly DependencyProperty SourceProperty = |
|
38 |
DependencyProperty.Register("MediaSource", typeof(String), typeof(VideoViewer), new PropertyMetadata("")); |
|
39 |
||
| 15 | 40 |
private bool _isPlayed = false; |
| 0 | 41 |
public VideoViewer() |
42 |
{ |
|
43 |
// Required to initialize variables |
|
| 22 | 44 |
InitializeComponent(); /// <summary> |
| 25 | 45 |
VideoScreen.MediaEnded += new RoutedEventHandler(VideoScreen_MediaEnded); |
46 |
VideoScreen.MediaOpened += new RoutedEventHandler(VideoScreen_MediaOpened); |
|
| 35 | 47 |
VideoPositionTimer.Interval = new System.TimeSpan(0, 0, 0, 0, 500); |
| 22 | 48 |
VideoPositionTimer.Tick += new EventHandler(VideoPositionTimer_Tick); |
| 0 | 49 |
Commands.GoToTime.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(GoToTime_Executed); |
50 |
Commands.VideoViewer.Pause.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Pause_Executed); |
|
51 |
Commands.VideoViewer.Play.Executed +=new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Play_Executed); |
|
| 35 | 52 |
|
53 |
|
|
| 29 | 54 |
|
55 |
} |
|
| 0 | 56 |
|
| 25 | 57 |
void VideoScreen_MediaOpened(object sender, RoutedEventArgs e) |
58 |
{ |
|
| 36 | 59 |
/* |
60 |
* In Order to begin |
|
61 |
*/ |
|
62 |
VideoScreen.Position = ((VideoViewerVM)DataContext).BeginIn; |
|
| 26 | 63 |
//VideoScreen.Play(); |
64 |
//VideoPositionTimer.Start(); |
|
| 25 | 65 |
|
66 |
} |
|
67 |
||
68 |
void VideoScreen_MediaEnded(object sender, RoutedEventArgs e) |
|
69 |
{ |
|
70 |
VideoPositionTimer.Stop(); |
|
71 |
} |
|
72 |
||
73 |
private void GoToTime_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
| 0 | 74 |
{ |
| 24 | 75 |
if (e.Source == DataContext && e.Source != null) |
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
76 |
{ |
| 35 | 77 |
//if(!VideoPositionTimer.IsEnabled) |
78 |
//VideoPositionTimer.Start(); |
|
| 25 | 79 |
|
| 26 | 80 |
VideoScreen.Position = ((TimeSpan)e.Parameter); |
| 25 | 81 |
|
| 24 | 82 |
|
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
83 |
} |
| 0 | 84 |
} |
85 |
||
86 |
void VideoPositionTimer_Tick(object sender, EventArgs e) |
|
87 |
{ |
|
| 22 | 88 |
if (_isPlayed) |
89 |
{ |
|
90 |
if(Tick!=null) |
|
91 |
{ |
|
92 |
Tick(this, new VideoViewerEventArgs(VideoScreen.Position)); |
|
93 |
} |
|
94 |
((VideoViewerVM)DataContext).LaunchTick(VideoScreen.Position); |
|
95 |
} |
|
96 |
//Commands.VideoViewer.SendPosition.Execute(VideoScreen.Position); |
|
| 0 | 97 |
} |
98 |
public void ChangePosition(TimeSpan TS) |
|
99 |
{ |
|
100 |
VideoScreen.Position = TS; |
|
101 |
|
|
102 |
} |
|
103 |
void Pause_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
104 |
{ |
|
| 25 | 105 |
if(e.Source == DataContext || e.Parameter == DataContext) |
| 0 | 106 |
{ |
| 25 | 107 |
VideoScreen.Pause(); |
108 |
_isPlayed = false; |
|
109 |
VideoPositionTimer.Stop(); |
|
| 38 | 110 |
if (DataContext != null) |
111 |
{ |
|
112 |
((VideoViewerVM)DataContext).AutoPlay = false; |
|
113 |
((VideoViewerVM)DataContext).IsPLayed = false; |
|
114 |
} |
|
| 0 | 115 |
} |
116 |
} |
|
117 |
||
118 |
void Play_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
119 |
{ |
|
| 30 | 120 |
if ((e.Parameter == DataContext || e.Parameter == null) && VideoScreen.Source != null) |
| 0 | 121 |
{ |
| 15 | 122 |
_isPlayed = true; |
| 0 | 123 |
VideoScreen.Play(); |
| 22 | 124 |
VideoPositionTimer.Start(); |
| 38 | 125 |
{ |
126 |
((VideoViewerVM)DataContext).AutoPlay = true; |
|
127 |
((VideoViewerVM)DataContext).IsPLayed = true; |
|
128 |
} |
|
| 0 | 129 |
} |
130 |
} |
|
131 |
||
132 |
private void VideoScreen_MediaFailed(object sender, System.Windows.ExceptionRoutedEventArgs e) |
|
133 |
{ |
|
134 |
MessageBox.Show(e.ErrorException.ToString()); |
|
135 |
} |
|
136 |
||
| 25 | 137 |
|
| 0 | 138 |
|
139 |
private void VideoScreen_MarkerReached(object sender, System.Windows.Media.TimelineMarkerRoutedEventArgs e) |
|
140 |
{ |
|
141 |
MessageBox.Show("toto"); |
|
142 |
} |
|
| 22 | 143 |
public event EventHandler<VideoViewerEventArgs> Tick; |
| 0 | 144 |
} |
| 22 | 145 |
public class VideoViewerEventArgs: EventArgs |
146 |
{ |
|
147 |
||
148 |
public TimeSpan Position { get; set; } |
|
149 |
public VideoViewerEventArgs(TimeSpan pos) |
|
150 |
{ |
|
151 |
Position = pos; |
|
152 |
} |
|
153 |
} |
|
| 0 | 154 |
} |