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