| author | Matthieu Totet |
| Tue, 22 Dec 2009 16:22:22 +0100 | |
| changeset 26 | 44a2dc869e28 |
| parent 25 | a9c815025a1b |
| child 29 | 5f8d275750e7 |
| 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> |
| 25 | 44 |
VideoScreen.MediaEnded += new RoutedEventHandler(VideoScreen_MediaEnded); |
45 |
VideoScreen.MediaOpened += new RoutedEventHandler(VideoScreen_MediaOpened); |
|
| 22 | 46 |
VideoPositionTimer.Interval = new System.TimeSpan(0, 0, 0, 0, 1000); |
47 |
VideoPositionTimer.Tick += new EventHandler(VideoPositionTimer_Tick); |
|
| 0 | 48 |
Commands.GoToTime.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(GoToTime_Executed); |
49 |
Commands.VideoViewer.Pause.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Pause_Executed); |
|
50 |
Commands.VideoViewer.Play.Executed +=new EventHandler<SLExtensions.Input.ExecutedEventArgs>(Play_Executed); |
|
51 |
} |
|
52 |
||
| 25 | 53 |
void VideoScreen_MediaOpened(object sender, RoutedEventArgs e) |
54 |
{ |
|
| 26 | 55 |
//VideoScreen.Play(); |
56 |
//VideoPositionTimer.Start(); |
|
| 25 | 57 |
|
58 |
} |
|
59 |
||
60 |
void VideoScreen_MediaEnded(object sender, RoutedEventArgs e) |
|
61 |
{ |
|
62 |
VideoPositionTimer.Stop(); |
|
63 |
} |
|
64 |
||
65 |
private void GoToTime_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
| 0 | 66 |
{ |
| 24 | 67 |
if (e.Source == DataContext && e.Source != null) |
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
68 |
{ |
| 26 | 69 |
if(!VideoPositionTimer.IsEnabled) |
| 25 | 70 |
VideoPositionTimer.Start(); |
71 |
|
|
| 26 | 72 |
VideoScreen.Position = ((TimeSpan)e.Parameter); |
| 25 | 73 |
|
| 24 | 74 |
|
|
23
10acb6a11a73
Update VideoViewer ( Allow Multi-VideoViewer)
Matthieu Totet
parents:
22
diff
changeset
|
75 |
} |
| 0 | 76 |
} |
77 |
||
78 |
void VideoPositionTimer_Tick(object sender, EventArgs e) |
|
79 |
{ |
|
| 22 | 80 |
if (_isPlayed) |
81 |
{ |
|
82 |
if(Tick!=null) |
|
83 |
{ |
|
84 |
Tick(this, new VideoViewerEventArgs(VideoScreen.Position)); |
|
85 |
} |
|
86 |
((VideoViewerVM)DataContext).LaunchTick(VideoScreen.Position); |
|
87 |
} |
|
88 |
//Commands.VideoViewer.SendPosition.Execute(VideoScreen.Position); |
|
| 0 | 89 |
} |
90 |
public void ChangePosition(TimeSpan TS) |
|
91 |
{ |
|
92 |
VideoScreen.Position = TS; |
|
93 |
|
|
94 |
} |
|
95 |
void Pause_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
96 |
{ |
|
| 25 | 97 |
if(e.Source == DataContext || e.Parameter == DataContext) |
| 0 | 98 |
{ |
| 25 | 99 |
VideoScreen.Pause(); |
100 |
_isPlayed = false; |
|
101 |
VideoPositionTimer.Stop(); |
|
| 26 | 102 |
if(DataContext!=null) |
103 |
((VideoViewerVM)DataContext).AutoPlay = false; |
|
| 0 | 104 |
} |
105 |
} |
|
106 |
||
107 |
void Play_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
108 |
{ |
|
109 |
if (e.Parameter == DataContext || e.Parameter == null) |
|
110 |
{ |
|
| 15 | 111 |
_isPlayed = true; |
| 0 | 112 |
VideoScreen.Play(); |
| 22 | 113 |
VideoPositionTimer.Start(); |
| 26 | 114 |
((VideoViewerVM)DataContext).AutoPlay = true; |
| 0 | 115 |
} |
116 |
} |
|
117 |
||
118 |
private void VideoScreen_MediaFailed(object sender, System.Windows.ExceptionRoutedEventArgs e) |
|
119 |
{ |
|
120 |
MessageBox.Show(e.ErrorException.ToString()); |
|
121 |
} |
|
122 |
||
| 25 | 123 |
|
| 0 | 124 |
|
125 |
private void VideoScreen_MarkerReached(object sender, System.Windows.Media.TimelineMarkerRoutedEventArgs e) |
|
126 |
{ |
|
127 |
MessageBox.Show("toto"); |
|
128 |
} |
|
| 22 | 129 |
public event EventHandler<VideoViewerEventArgs> Tick; |
| 0 | 130 |
} |
| 22 | 131 |
public class VideoViewerEventArgs: EventArgs |
132 |
{ |
|
133 |
||
134 |
public TimeSpan Position { get; set; } |
|
135 |
public VideoViewerEventArgs(TimeSpan pos) |
|
136 |
{ |
|
137 |
Position = pos; |
|
138 |
} |
|
139 |
} |
|
| 0 | 140 |
} |