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