Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dougrathbone/open-attractor
base: 04447328a7
...
head fork: dougrathbone/open-attractor
compare: b445002bdc
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
View
1  OpenAttractor/App.config
@@ -10,5 +10,6 @@
<add key="NoTouchClearScreenTimer" value="900"/>
<add key="NoTouchThrobTimer" value="20"/>
<add key="EnableDebug" value="false"/>
+ <add key="MaximumVideosPlayingAtOnce" value="4"/>
</appSettings>
</configuration>
View
13 OpenAttractor/AppSettings.cs
@@ -59,5 +59,18 @@ public static int MaximumAssetWidth
: 1920;
}
}
+
+ public static int MaximumVideosPlayingAtOnce
+ {
+ get
+ {
+ var settingValue = ConfigurationManager.AppSettings["MaximumVideosPlayingAtOnce"];
+ int temp;
+
+ return settingValue != null && int.TryParse(settingValue, out temp)
+ ? temp
+ : 2;
+ }
+ }
}
}
View
38 OpenAttractor/Helpers/AnimationHelper.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Media.Animation;
+
+namespace OpenAttractor.Helpers
+{
+ public class AnimationHelper
+ {
+ public static void RunScaleAnimation(FrameworkElement e)
+ {
+ var storyboard = new Storyboard();
+ var easeOut = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.3 };
+
+ var startHeight = e.ActualHeight;
+ var startWidth = e.ActualWidth;
+
+ var growAnimationHOut = new DoubleAnimation(startHeight, startHeight * 1.05,
+ TimeSpan.FromMilliseconds(70)) { AutoReverse = true };
+
+ var growAnimationWOut = new DoubleAnimation(startWidth, startWidth * 1.05,
+ TimeSpan.FromMilliseconds(70)) { AutoReverse = true };
+
+ growAnimationHOut.EasingFunction = easeOut;
+ growAnimationWOut.EasingFunction = easeOut;
+
+ storyboard.Children.Add(growAnimationHOut);
+ storyboard.Children.Add(growAnimationWOut);
+
+ Storyboard.SetTargetProperty(growAnimationWOut, new PropertyPath(FrameworkElement.WidthProperty));
+ Storyboard.SetTargetProperty(growAnimationHOut, new PropertyPath(FrameworkElement.HeightProperty));
+
+ e.BeginStoryboard(storyboard);
+ }
+ }
+}
View
1  OpenAttractor/OpenAttractor.csproj
@@ -53,6 +53,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppSettings.cs" />
+ <Compile Include="Helpers\AnimationHelper.cs" />
<Compile Include="ImageViewer.xaml.cs">
<DependentUpon>ImageViewer.xaml</DependentUpon>
</Compile>
View
96 OpenAttractor/SurfaceWindow1.xaml.cs
@@ -1,5 +1,7 @@
using System;
+using System.Collections.Generic;
using System.Configuration;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
@@ -13,6 +15,7 @@
using System.Windows.Threading;
using Microsoft.Surface;
using Microsoft.Surface.Presentation.Controls;
+using OpenAttractor.Helpers;
using OpenAttractor.Properties;
using Timer = System.Timers.Timer;
@@ -23,8 +26,8 @@ namespace OpenAttractor
/// </summary>
public partial class SurfaceWindow1 : SurfaceWindow
{
- private Timer clearScreenTimer;
- private DateTime timeLastTouched = DateTime.MinValue;
+ private Timer _clearScreenTimer;
+ private DateTime _timeLastTouched = DateTime.MinValue;
public double TimeSinceLastTouch { get { return (double)GetValue(_timeSinceLastTouch); } set { SetValue(_timeSinceLastTouch, value); } }
public static readonly DependencyProperty _timeSinceLastTouch = DependencyProperty.Register("TimeSinceLastTouch", typeof(double), typeof(SurfaceWindow1), new FrameworkPropertyMetadata((double)0));
@@ -32,6 +35,7 @@ public partial class SurfaceWindow1 : SurfaceWindow
public string BackgroundImagePath { get { return (string)GetValue(_backgroundImagePath); } set { SetValue(_backgroundImagePath, value); } }
public static readonly DependencyProperty _backgroundImagePath = DependencyProperty.Register("BackgroundImagePath", typeof(string), typeof(SurfaceWindow1), new FrameworkPropertyMetadata(AppSettings.BackgroundPath));
+ private List<VideoPlayer> _videoPlayers;
public SurfaceWindow1()
{
@@ -39,9 +43,9 @@ public SurfaceWindow1()
// Add handlers for window availability events
AddWindowAvailabilityHandlers();
- Loaded += new RoutedEventHandler(SurfaceWindow1_Loaded);
- PreviewTouchDown += delegate(object sender, TouchEventArgs args) { FireClickEvent(); };
- PreviewMouseDown += delegate(object sender, MouseButtonEventArgs args) { FireClickEvent(); };
+ Loaded += SurfaceWindow1_Loaded;
+ PreviewTouchDown += delegate { FireClickEvent(); };
+ PreviewMouseDown += delegate { FireClickEvent(); };
}
void FireClickEvent()
@@ -50,14 +54,16 @@ void FireClickEvent()
DispatcherPriority.Background,
new Action(() =>
{
- timeLastTouched = DateTime.Now;
- throbObjects = false;
+ _timeLastTouched = DateTime.Now;
+ _throbObjects = false;
}));
}
void SurfaceWindow1_Loaded(object sender, RoutedEventArgs e)
{
- timeLastTouched = DateTime.Now;
+ _timeLastTouched = DateTime.Now;
+ _videoPlayers = new List<VideoPlayer>();
+
InitialiseTouchTimer();
TimeSinceLastTouchLabel.Visibility = Visibility.Collapsed;
@@ -67,7 +73,7 @@ void SurfaceWindow1_Loaded(object sender, RoutedEventArgs e)
private void InitialiseScatterItems()
{
-
+ _videoPlayers.ForEach(x=>x.StopVideo());
ScatterContainer.Items.Clear();
var images =
@@ -99,43 +105,41 @@ private void InitialiseScatterItems()
{
var videoControl = new VideoPlayer { Source = videoPath };
var scatterView = new ScatterViewItem { Content = videoControl, MaxWidth = AppSettings.MaximumAssetWidth };
+ videoControl.OnVideoPlayerPlayed += videoControl_OnVideoPlayerPlayed;
+ videoControl.OnVideoPlayerStopped += videoControl_VideoStopped;
+
ScatterContainer.Items.Add(scatterView);
+ _videoPlayers.Add(videoControl);
}
}
- void RunScaleAnimation(FrameworkElement e)
+ void videoControl_OnVideoPlayerPlayed(object sender, EventArgs e)
{
+ var videoPlayersPlaying = _videoPlayers.Count(x => x.VideoIsPlaying);
- var storyboard = new Storyboard();
- var easeOut = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.3 };
-
- var startHeight = e.ActualHeight;
- var startWidth = e.ActualWidth;
-
- var growAnimationHOut = new DoubleAnimation(startHeight, startHeight * 1.05,
- TimeSpan.FromMilliseconds(70)) { AutoReverse = true };
-
- var growAnimationWOut = new DoubleAnimation(startWidth, startWidth * 1.05,
- TimeSpan.FromMilliseconds(70)) { AutoReverse = true };
-
- growAnimationHOut.EasingFunction = easeOut;
- growAnimationWOut.EasingFunction = easeOut;
-
- storyboard.Children.Add(growAnimationHOut);
- storyboard.Children.Add(growAnimationWOut);
-
- Storyboard.SetTargetProperty(growAnimationWOut, new PropertyPath(WidthProperty));
- Storyboard.SetTargetProperty(growAnimationHOut, new PropertyPath(HeightProperty));
+ if (videoPlayersPlaying > AppSettings.MaximumVideosPlayingAtOnce)
+ {
+ var singleOrDefault = _videoPlayers.Where(x => x.VideoIsPlaying).OrderBy(x => x.PlayStarted).Take(1).SingleOrDefault();
+ if (singleOrDefault != null)
+ singleOrDefault.StopVideo();
+ Debug.WriteLine("Too many videos playing, stopping one");
+ }
+ Debug.WriteLine("Video player played");
+ Debug.WriteLine("{0} videos currently playing", videoPlayersPlaying);
+ }
- e.BeginStoryboard(storyboard);
+ void videoControl_VideoStopped(object sender, EventArgs e)
+ {
+ Debug.WriteLine("Video player stopped");
+ Debug.WriteLine("{0} videos currently playing", _videoPlayers.Count(x => x.VideoIsPlaying));
}
- private bool throbObjects = false;
+ private bool _throbObjects = false;
private void InitialiseTouchTimer()
{
- clearScreenTimer = new Timer { Interval = 2000 };
- clearScreenTimer.Elapsed += clearScreenTimer_Elapsed;
- clearScreenTimer.Enabled = true;
+ _clearScreenTimer = new Timer { Interval = 2000 };
+ _clearScreenTimer.Elapsed += clearScreenTimer_Elapsed;
+ _clearScreenTimer.Enabled = true;
}
void clearScreenTimer_Elapsed(object sender, ElapsedEventArgs e)
@@ -145,29 +149,29 @@ void clearScreenTimer_Elapsed(object sender, ElapsedEventArgs e)
new Action(
() =>
{
- TimeSinceLastTouch = ((TimeSpan)(DateTime.Now - timeLastTouched)).TotalSeconds;
+ TimeSinceLastTouch = (DateTime.Now - _timeLastTouched).TotalSeconds;
if (TimeSinceLastTouch > AppSettings.ClearScreenTimerInterval)
{
- timeLastTouched = DateTime.Now;
+ _timeLastTouched = DateTime.Now;
InitialiseScatterItems();
}
- if (TimeSinceLastTouch > AppSettings.ThrobTimerInterval && !throbObjects)
+ if (TimeSinceLastTouch > AppSettings.ThrobTimerInterval && !_throbObjects)
{
- throbObjects = true;
+ _throbObjects = true;
StartThrobStoryboards();
}
}));
}
- private int nextObject = 0;
+ private int _nextObjectIndex = 0;
private void StartThrobStoryboards()
{
- RunScaleAnimation((FrameworkElement)ScatterContainer.Items[nextObject]);
- nextObject++;
- if (nextObject >= ScatterContainer.Items.Count) nextObject = 0;
+ AnimationHelper.RunScaleAnimation((FrameworkElement)ScatterContainer.Items[_nextObjectIndex]);
+ _nextObjectIndex++;
+ if (_nextObjectIndex >= ScatterContainer.Items.Count) _nextObjectIndex = 0;
- throbObjects = false;
+ _throbObjects = false;
}
/// <summary>
@@ -178,8 +182,8 @@ protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
- throbObjects = false;
- clearScreenTimer.Enabled = false;
+ _throbObjects = false;
+ _clearScreenTimer.Enabled = false;
// Remove handlers for window availability events
RemoveWindowAvailabilityHandlers();
View
8 OpenAttractor/VideoPlayer.xaml
@@ -13,7 +13,7 @@
<ImageBrush ImageSource="/OpenAttractor;component/Resources/video_frame.png" />
</Grid.Background>
<MediaElement Margin="3" x:Name="videoPlayer" ScrubbingEnabled="True" Source="{Binding Path=Source}" Loaded="videoPlayer_Loaded" LoadedBehavior="Manual" UnloadedBehavior="Stop" Stretch="UniformToFill" />
- <Image Source="/OpenAttractor;component/Resources/video_overlay.png" x:Name="Overlay">
+ <Image Source="/OpenAttractor;component/Resources/video_overlay.png" Stretch="Fill" x:Name="Overlay">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
@@ -27,7 +27,11 @@
</Style>
</Image.Style>
</Image>
- <s:SurfaceButton x:Name="PlayButton" Click="PlayButton_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+<<<<<<< HEAD
+ <s:SurfaceButton x:Name="PlayButton" Click="PlayButton_Click" Background="Transparent" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+=======
+ <s:SurfaceButton Background="Transparent" x:Name="PlayButton" Click="PlayButton_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+>>>>>>> cf61b64d2acf29c252aa8b8b24955e20f0a492cd
<s:SurfaceButton.Content>
<Image Source="/OpenAttractor;component/Resources/video_playbutton_large.png">
<!--<Image.Style>
View
45 OpenAttractor/VideoPlayer.xaml.cs
@@ -6,6 +6,8 @@
namespace OpenAttractor
{
+ public delegate void ChangedEventHandler(object sender, EventArgs e);
+
public partial class VideoPlayer : UserControl
{
public string Source { get { return (string)GetValue(_sourceProperty); } set { SetValue(_sourceProperty, value); } }
@@ -19,6 +21,23 @@ public partial class VideoPlayer : UserControl
private Timer _playTimer;
+ public DateTime? PlayStarted { get; set; }
+
+ public event ChangedEventHandler OnVideoPlayerPlayed;
+ protected virtual void OnPlayed(EventArgs e)
+ {
+ PlayStarted = DateTime.Now;
+ if (OnVideoPlayerPlayed != null)
+ OnVideoPlayerPlayed(this, e);
+ }
+ public event ChangedEventHandler OnVideoPlayerStopped;
+ protected virtual void OnStopped(EventArgs e)
+ {
+ PlayStarted = null;
+ if (OnVideoPlayerStopped != null)
+ OnVideoPlayerStopped(this, e);
+ }
+
public VideoPlayer()
{
InitializeComponent();
@@ -46,9 +65,7 @@ void VideoPlayerLoaded(object sender, RoutedEventArgs e)
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
- videoPlayer.Play();
- _playTimer.Start();
- VideoIsPlaying = true;
+ PlayVideo();
}
private void RewindButton_Click(object sender, RoutedEventArgs e)
@@ -56,11 +73,25 @@ private void RewindButton_Click(object sender, RoutedEventArgs e)
videoPlayer.Position = new TimeSpan(0, 0, 0, 0);
}
- private void PauseButton_Click(object sender, RoutedEventArgs e)
+ public void StopVideo()
{
videoPlayer.Pause();
_playTimer.Stop();
- VideoIsPlaying = false;
+ VideoIsPlaying = false;
+ OnStopped(EventArgs.Empty);
+ }
+
+ public void PlayVideo()
+ {
+ videoPlayer.Play();
+ _playTimer.Start();
+ VideoIsPlaying = true;
+ OnPlayed(EventArgs.Empty);
+ }
+
+ private void PauseButton_Click(object sender, RoutedEventArgs e)
+ {
+ StopVideo();
}
private void videoPlayer_Loaded(object sender, RoutedEventArgs e)
@@ -72,9 +103,7 @@ private void videoPlayer_Loaded(object sender, RoutedEventArgs e)
private void PlayButtonSmall_Click(object sender, RoutedEventArgs e)
{
- videoPlayer.Play();
- _playTimer.Start();
- VideoIsPlaying = true;
+ PlayVideo();
}
}
}

No commit comments for this range

Something went wrong with that request. Please try again.