diff -r 215a7412e544 -r e8bfe1102e03 src/FingersDance.Control.TimeLine/SurfaceTimeLineTest.xaml.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.Control.TimeLine/SurfaceTimeLineTest.xaml.cs Mon Aug 03 22:36:46 2009 +0200
@@ -0,0 +1,254 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.Windows.Threading;
+using Microsoft.Surface;
+using Microsoft.Surface.Presentation;
+using Microsoft.Surface.Presentation.Controls;
+
+namespace FingersDance.Control.TimeLine
+{
+ ///
+ /// Interaction logic for SurfaceWindow1.xaml
+ ///
+ public partial class SurfaceTimeLineTest : SurfaceWindow
+ {
+
+ DispatcherTimer timer; // handles position of slider and player
+ bool isDragging = false;
+ bool isPlaying = false;
+
+
+
+ ///
+ /// Default constructor.
+ ///
+ public SurfaceTimeLineTest()
+ {
+ InitializeComponent();
+
+ // Add handlers for Application activation events
+ initplayer();
+ AddActivationHandlers();
+ }
+
+ #region Handlers
+ ///
+ /// Occurs when the window is about to close.
+ ///
+ ///
+ protected override void OnClosed(EventArgs e)
+ {
+ base.OnClosed(e);
+
+ // Remove handlers for Application activation events
+ RemoveActivationHandlers();
+ }
+
+ ///
+ /// Adds handlers for Application activation events.
+ ///
+ private void AddActivationHandlers()
+ {
+ // Subscribe to surface application activation events
+ ApplicationLauncher.ApplicationActivated += OnApplicationActivated;
+ ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed;
+ ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated;
+ }
+
+ ///
+ /// Removes handlers for Application activation events.
+ ///
+ private void RemoveActivationHandlers()
+ {
+ // Unsubscribe from surface application activation events
+ ApplicationLauncher.ApplicationActivated -= OnApplicationActivated;
+ ApplicationLauncher.ApplicationPreviewed -= OnApplicationPreviewed;
+ ApplicationLauncher.ApplicationDeactivated -= OnApplicationDeactivated;
+ }
+
+ ///
+ /// This is called when application has been activated.
+ ///
+ ///
+ ///
+ private void OnApplicationActivated(object sender, EventArgs e)
+ {
+ //TODO: enable audio, animations here
+ }
+
+ ///
+ /// This is called when application is in preview mode.
+ ///
+ ///
+ ///
+ private void OnApplicationPreviewed(object sender, EventArgs e)
+ {
+ //TODO: Disable audio here if it is enabled
+
+ //TODO: optionally enable animations here
+ }
+
+ ///
+ /// This is called when application has been deactivated.
+ ///
+ ///
+ ///
+ private void OnApplicationDeactivated(object sender, EventArgs e)
+ {
+ //TODO: disable audio, animations here
+ }
+ #endregion
+
+ #region SurfaceWindows events
+
+ private void SurfaceWindow_Activated(object sender, EventArgs e)
+ {
+ timer = new DispatcherTimer();
+ //timer.Interval = TimeSpan.FromSeconds(1);
+ timer.Interval = TimeSpan.FromMilliseconds(250);
+ timer.Tick += new EventHandler(timer_Tick);
+ }
+ #endregion
+
+ #region Timer
+ void timer_Tick(object sender, EventArgs e)
+ {
+ //Slider Position
+ labelPosition.Content = sliderBase.Value;
+ //Media Position ToString and TotalMilliseconds
+ labelMediaPositionToString.Content=mediaelement.Position.ToString();
+ labelMediaPositionContent.Content = mediaelement.Position.TotalMilliseconds;
+ //Si le slider n'est pas en train d'etre bougé, on change sa valeur
+ if (!isDragging)
+ {
+ sliderBase.Value = mediaelement.Position.TotalMilliseconds;
+ }
+
+ }
+ #endregion
+
+ #region MediaElement events
+ private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
+ {
+ mediaelement.Stop();
+ }
+
+ private void mediaelement_MediaOpened(object sender, RoutedEventArgs e)
+ {
+ labelDuration.Content = mediaelement.NaturalDuration.ToString();
+
+ sliderBase.Maximum = mediaelement.NaturalDuration.TimeSpan.TotalMilliseconds;
+ labelSliderMax.Content = sliderBase.Maximum;
+ //initialisation du timer
+ timer.Start();
+ }
+ #endregion
+
+ #region Slider
+
+ private void sliderBase_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
+ {
+ //TODO
+ if (!isDragging)
+ {
+
+ int SliderValue = (int)sliderBase.Value;
+
+ // Overloaded constructor takes the arguments days, hours, minutes, seconds, miniseconds.
+ // Create a TimeSpan with miliseconds equal to the slider value.
+ TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
+ mediaelement.Position = ts;
+ mediaelement.Play();
+ }
+
+ }
+
+ private void sliderBase_DragEnter(object sender, DragEventArgs e)
+ {
+ isDragging = true;
+ mediaelement.Pause();
+ }
+
+ private void sliderBase_DragLeave(object sender, DragEventArgs e)
+ {
+ isDragging = false;
+ //mediaelement.Position = TimeSpan.FromSeconds(sliderBase.Value);
+
+ }
+
+ private void sliderBase_ContactEnter(object sender, ContactEventArgs e)
+ {
+ isDragging = true;
+ mediaelement.Pause();
+ }
+
+ private void sliderBase_ContactLeave(object sender, ContactEventArgs e)
+ {
+ isDragging = false;
+ mediaelement.Position = TimeSpan.FromSeconds(sliderBase.Value);
+ }
+
+ private void sliderBase_ContactChanged(object sender, ContactEventArgs e)
+ {
+ // isDragging = false;
+ //mediaelement.Position = TimeSpan.FromMilliseconds(sliderBase.Value);
+ }
+ #endregion
+
+ #region Player
+ private void initplayer()
+ {
+ mediaelement.LoadedBehavior = MediaState.Manual;
+ }
+
+ private void butonPlayPause_Click(object sender, RoutedEventArgs e)
+ {
+ if (!isPlaying)//Play
+ {
+ isPlaying = true;
+ try
+ {
+ mediaelement.Play();
+ }
+ catch (Exception ex) { }
+ }
+ else//Pause
+ {
+ isPlaying = false;
+ try
+ {
+ mediaelement.Pause();
+ }
+ catch (Exception exx) { }
+ }
+ }
+ private void SurfaceButton_Click(object sender, RoutedEventArgs e)
+ {
+ mediaelement.Stop();
+ }
+
+ private void SurfaceButton_ContactDown(object sender, ContactEventArgs e)
+ {
+ mediaelement.Stop();
+ }
+
+ #endregion
+
+
+
+
+
+ }
+
+
+}
\ No newline at end of file