| author | Matthieu Totet |
| Wed, 16 Dec 2009 17:14:38 +0100 | |
| changeset 24 | c031f1132dde |
| parent 23 | 10acb6a11a73 |
| child 25 | a9c815025a1b |
| 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 |
{ |
|
25 |
return (String)GetValue(SourceProperty); |
|
26 |
} |
|
27 |
set |
|
28 |
{ |
|
29 |
SetValue(SourceProperty, value); |
|
30 |
if(DataContext != null) |
|
31 |
((VideoViewerVM)DataContext).Source = value; |
|
32 |
} |
|
33 |
} |
|
34 |
||
35 |
// Using a DependencyProperty as the backing store for Source. This enables animation, styling, binding, etc... |
|
36 |
public static readonly DependencyProperty SourceProperty = |
|
37 |
DependencyProperty.Register("MediaSource", typeof(String), typeof(VideoViewer), new PropertyMetadata("")); |
|
38 |
||
| 15 | 39 |
private bool _isPlayed = false; |
| 0 | 40 |
public VideoViewer() |
41 |
{ |
|
42 |
// Required to initialize variables |
|
| 22 | 43 |
InitializeComponent(); /// <summary> |
44 |
VideoPositionTimer.Interval = new System.TimeSpan(0, 0, 0, 0, 1000); |
|
45 |
VideoPositionTimer.Tick += new EventHandler(VideoPositionTimer_Tick); |
|
| 0 | 46 |
Commands.GoToTime.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(GoToTime_Executed); |
47 |
Commands.VideoViewer.Pause.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Pause_Executed); |
|
48 |
Commands.VideoViewer.Play.Executed +=new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Play_Executed); |
|
49 |
} |
|
50 |
||
51 |
void GoToTime_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
52 |
{ |
|
| 24 | 53 |
if (e.Source == DataContext && e.Source != null) |
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
54 |
{ |
| 24 | 55 |
VideoScreen.Pause(); |
56 |
VideoScreen.Position = new TimeSpan(((TimeSpan)e.Parameter).Ticks); |
|
57 |
|
|
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
58 |
} |
| 0 | 59 |
} |
60 |
||
61 |
void VideoPositionTimer_Tick(object sender, EventArgs e) |
|
62 |
{ |
|
| 22 | 63 |
if (_isPlayed) |
64 |
{ |
|
65 |
if(Tick!=null) |
|
66 |
{ |
|
67 |
Tick(this, new VideoViewerEventArgs(VideoScreen.Position)); |
|
68 |
} |
|
69 |
((VideoViewerVM)DataContext).LaunchTick(VideoScreen.Position); |
|
70 |
} |
|
71 |
//Commands.VideoViewer.SendPosition.Execute(VideoScreen.Position); |
|
| 0 | 72 |
} |
73 |
public void ChangePosition(TimeSpan TS) |
|
74 |
{ |
|
75 |
VideoScreen.Position = TS; |
|
76 |
|
|
77 |
} |
|
78 |
void Pause_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
79 |
{ |
|
80 |
VideoScreen.Pause(); |
|
| 15 | 81 |
_isPlayed = false; |
| 22 | 82 |
VideoPositionTimer.Stop(); |
83 |
if (VideoPositionTimer.IsEnabled) |
|
| 0 | 84 |
{ |
85 |
MessageBox.Show("Click Time IS NOT STOPPED"); |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
void Play_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
90 |
{ |
|
91 |
if (e.Parameter == DataContext || e.Parameter == null) |
|
92 |
{ |
|
| 15 | 93 |
_isPlayed = true; |
| 0 | 94 |
VideoScreen.Play(); |
| 22 | 95 |
VideoPositionTimer.Start(); |
| 0 | 96 |
} |
97 |
} |
|
98 |
||
99 |
private void VideoScreen_MediaFailed(object sender, System.Windows.ExceptionRoutedEventArgs e) |
|
100 |
{ |
|
101 |
MessageBox.Show(e.ErrorException.ToString()); |
|
102 |
} |
|
103 |
||
104 |
private void VideoScreen_CurrentStateChanged(object sender, System.Windows.RoutedEventArgs e) |
|
105 |
{ |
|
106 |
|
|
107 |
} |
|
108 |
||
109 |
private void VideoScreen_MarkerReached(object sender, System.Windows.Media.TimelineMarkerRoutedEventArgs e) |
|
110 |
{ |
|
111 |
MessageBox.Show("toto"); |
|
112 |
} |
|
| 22 | 113 |
public event EventHandler<VideoViewerEventArgs> Tick; |
| 0 | 114 |
} |
| 22 | 115 |
public class VideoViewerEventArgs: EventArgs |
116 |
{ |
|
117 |
||
118 |
public TimeSpan Position { get; set; } |
|
119 |
public VideoViewerEventArgs(TimeSpan pos) |
|
120 |
{ |
|
121 |
Position = pos; |
|
122 |
} |
|
123 |
} |
|
| 0 | 124 |
} |