From 01cf83532d3a749a4705f763f805fc363f53a4fd Mon Sep 17 00:00:00 2001 From: Zippy Date: Sun, 27 Dec 2009 13:44:45 +0100 Subject: initial silverlight - webapp import Signed-off-by: Zippy --- src/YalpClients/WebClient/App.xaml | 8 + src/YalpClients/WebClient/App.xaml.cs | 66 +++++ src/YalpClients/WebClient/Default.aspx.cs | 22 ++ src/YalpClients/WebClient/Default.aspx.designer.cs | 70 +++++ src/YalpClients/WebClient/MainPage.xaml | 284 +++++++++++++++++++++ src/YalpClients/WebClient/MainPage.xaml.cs | 198 ++++++++++++++ .../WebClient/Properties/AppManifest.xml | 16 ++ .../WebClient/Properties/AssemblyInfo.cs | 35 +++ src/YalpClients/WebClient/VideoPlayer.csproj | 103 ++++++++ src/YalpClients/WebClient/VideoPlayer.csproj.user | 28 ++ src/YalpClients/WebClient/VideoPlayer.sln | 20 ++ 11 files changed, 850 insertions(+) create mode 100644 src/YalpClients/WebClient/App.xaml create mode 100644 src/YalpClients/WebClient/App.xaml.cs create mode 100644 src/YalpClients/WebClient/Default.aspx.cs create mode 100644 src/YalpClients/WebClient/Default.aspx.designer.cs create mode 100644 src/YalpClients/WebClient/MainPage.xaml create mode 100644 src/YalpClients/WebClient/MainPage.xaml.cs create mode 100644 src/YalpClients/WebClient/Properties/AppManifest.xml create mode 100644 src/YalpClients/WebClient/Properties/AssemblyInfo.cs create mode 100644 src/YalpClients/WebClient/VideoPlayer.csproj create mode 100644 src/YalpClients/WebClient/VideoPlayer.csproj.user create mode 100644 src/YalpClients/WebClient/VideoPlayer.sln (limited to 'src') diff --git a/src/YalpClients/WebClient/App.xaml b/src/YalpClients/WebClient/App.xaml new file mode 100644 index 0000000..48a0475 --- /dev/null +++ b/src/YalpClients/WebClient/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/src/YalpClients/WebClient/App.xaml.cs b/src/YalpClients/WebClient/App.xaml.cs new file mode 100644 index 0000000..2a30f24 --- /dev/null +++ b/src/YalpClients/WebClient/App.xaml.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +namespace VideoPlayer +{ + public partial class App : Application + { + + public App() + { + this.Startup += this.Application_Startup; + this.Exit += this.Application_Exit; + this.UnhandledException += this.Application_UnhandledException; + + InitializeComponent(); + } + + private void Application_Startup(object sender, StartupEventArgs e) + { + this.RootVisual = new MainPage(); + } + + private void Application_Exit(object sender, EventArgs e) + { + + } + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + // If the app is running outside of the debugger then report the exception using + // the browser's exception mechanism. On IE this will display it a yellow alert + // icon in the status bar and Firefox will display a script error. + if (!System.Diagnostics.Debugger.IsAttached) + { + + // NOTE: This will allow the application to continue running after an exception has been thrown + // but not handled. + // For production applications this error handling should be replaced with something that will + // report the error to the website and stop the application. + e.Handled = true; + Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); + } + } + private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) + { + try + { + string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; + errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); + + System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");"); + } + catch (Exception) + { + } + } + } +} diff --git a/src/YalpClients/WebClient/Default.aspx.cs b/src/YalpClients/WebClient/Default.aspx.cs new file mode 100644 index 0000000..0bd1d7d --- /dev/null +++ b/src/YalpClients/WebClient/Default.aspx.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace TwitterSearchApplication.Web +{ + public partial class _Default : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + + } + + protected void Button1_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/src/YalpClients/WebClient/Default.aspx.designer.cs b/src/YalpClients/WebClient/Default.aspx.designer.cs new file mode 100644 index 0000000..6b1c246 --- /dev/null +++ b/src/YalpClients/WebClient/Default.aspx.designer.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:2.0.50727.4200 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace TwitterSearchApplication.Web { + + + public partial class _Default { + + /// + /// form1-Steuerelement + /// + /// + /// Automatisch generiertes Feld + /// Um dies zu ändern, verschieben Sie die Felddeklaration aus der Designerdatei in eine Code-Behind-Datei. + /// + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// + /// Checkbox1-Steuerelement + /// + /// + /// Automatisch generiertes Feld + /// Um dies zu ändern, verschieben Sie die Felddeklaration aus der Designerdatei in eine Code-Behind-Datei. + /// + protected global::System.Web.UI.WebControls.CheckBox Checkbox1; + + /// + /// Button1-Steuerelement + /// + /// + /// Automatisch generiertes Feld + /// Um dies zu ändern, verschieben Sie die Felddeklaration aus der Designerdatei in eine Code-Behind-Datei. + /// + protected global::System.Web.UI.WebControls.Button Button1; + + /// + /// TextBox1-Steuerelement + /// + /// + /// Automatisch generiertes Feld + /// Um dies zu ändern, verschieben Sie die Felddeklaration aus der Designerdatei in eine Code-Behind-Datei. + /// + protected global::System.Web.UI.WebControls.TextBox TextBox1; + + /// + /// TextBox2-Steuerelement + /// + /// + /// Automatisch generiertes Feld + /// Um dies zu ändern, verschieben Sie die Felddeklaration aus der Designerdatei in eine Code-Behind-Datei. + /// + protected global::System.Web.UI.WebControls.TextBox TextBox2; + + /// + /// RadioButton1-Steuerelement + /// + /// + /// Automatisch generiertes Feld + /// Um dies zu ändern, verschieben Sie die Felddeklaration aus der Designerdatei in eine Code-Behind-Datei. + /// + protected global::System.Web.UI.WebControls.RadioButton RadioButton1; + } +} diff --git a/src/YalpClients/WebClient/MainPage.xaml b/src/YalpClients/WebClient/MainPage.xaml new file mode 100644 index 0000000..462b529 --- /dev/null +++ b/src/YalpClients/WebClient/MainPage.xaml @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/YalpClients/WebClient/MainPage.xaml.cs b/src/YalpClients/WebClient/MainPage.xaml.cs new file mode 100644 index 0000000..aa392f2 --- /dev/null +++ b/src/YalpClients/WebClient/MainPage.xaml.cs @@ -0,0 +1,198 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +namespace VideoPlayer +{ + // For best full-screen video performance, set EnableGPUAcceleration="true" on the plug-in. + // If hosting Silverlight from .aspx, add EnableGPUAcceleration="true" to the + // element. If hosting Silverlight from .html, add + // under the tag. + + public partial class MainPage : UserControl + { + // mediaElement.Position updates TimelineSlider.Value, and + // updating TimelineSlider.Value updates mediaElement.Position, + // this variable helps us break the infinite loop + private bool duringTickEvent = false; + + private bool playVideoWhenSliderDragIsOver = false; + + public MainPage() + { + InitializeComponent(); + + mediaElement.Source = new Uri("file:///D:/Test/countdown.wmv"); + //mit Datei: + //mediaElement.Source = new Uri("file:///D:/Test/countdown.wmv"); + //http://www.shoutcast.com/shoutcast_player?stationid=7806&Genre=Electronic&ContentFlag=1 + // + CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); + Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged); + } + + private void MediaElement_MediaOpened(object sender, RoutedEventArgs e) + { + TimeSpan duration = mediaElement.NaturalDuration.TimeSpan; + totalTimeTextBlock.Text = TimeSpanToString(duration); + UpdateVideoSize(); + } + + #region play button + + private void BigPlayButton_Click(object sender, RoutedEventArgs e) + { + playPauseButton.IsChecked = true; + PlayPauseButton_Click(sender, e); + } + + private void PlayPauseButton_Click(object sender, RoutedEventArgs e) + { + bigPlayButton.Visibility = Visibility.Collapsed; + + // this will be the toggle button state after the click has been processed + if (playPauseButton.IsChecked == true) + mediaElement.Play(); + else + mediaElement.Pause(); + } + + #endregion + + #region timelineSlider + + private void Seek(double percentComplete) + { + if (duringTickEvent) + throw new Exception("Can't call Seek() now, you'll get an infinite loop"); + + TimeSpan duration = mediaElement.NaturalDuration.TimeSpan; + int newPosition = (int)(duration.TotalSeconds * percentComplete); + mediaElement.Position = new TimeSpan(0, 0, newPosition); + + // let the next CompositionTarget.Rendering take care of updating the text blocks + } + + private Slider GetSliderParent(object sender) + { + FrameworkElement element = (FrameworkElement)sender; + do + { + element = (FrameworkElement)VisualTreeHelper.GetParent(element); + } while (!(element is Slider)); + return (Slider)element; + } + + private void LeftTrack_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + e.Handled = true; + FrameworkElement lefttrack = (sender as FrameworkElement).FindName("LeftTrack") as FrameworkElement; + FrameworkElement righttrack = (sender as FrameworkElement).FindName("RightTrack") as FrameworkElement; + double position = e.GetPosition(lefttrack).X; + double width = righttrack.TransformToVisual(lefttrack).Transform(new Point(righttrack.ActualWidth, righttrack.ActualHeight)).X; + double percent = position / width; + Slider slider = GetSliderParent(sender); + slider.Value = percent; + } + + private void HorizontalThumb_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) + { + if (GetSliderParent(sender) != timelineSlider) return; + + bool notPlaying = (mediaElement.CurrentState == MediaElementState.Paused + || mediaElement.CurrentState == MediaElementState.Stopped); + + if (notPlaying) + { + playVideoWhenSliderDragIsOver = false; + } + else + { + playVideoWhenSliderDragIsOver = true; + mediaElement.Pause(); + } + } + + private void HorizontalThumb_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) + { + if (playVideoWhenSliderDragIsOver) + mediaElement.Play(); + } + + private void TimelineSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + if (duringTickEvent) + return; + + Seek(timelineSlider.Value); + } + + #endregion + + #region updating current time + + private void CompositionTarget_Rendering(object sender, EventArgs e) + { + duringTickEvent = true; + + TimeSpan duration = mediaElement.NaturalDuration.TimeSpan; + if (duration.TotalSeconds != 0) + { + double percentComplete = (mediaElement.Position.TotalSeconds / duration.TotalSeconds); + timelineSlider.Value = percentComplete; + string text = TimeSpanToString(mediaElement.Position); + if (this.currentTimeTextBlock.Text != text) + this.currentTimeTextBlock.Text = text; + } + + duringTickEvent = false; + } + + private static string TimeSpanToString(TimeSpan time) + { + return string.Format("{0:00}:{1:00}", (time.Hours * 60) + time.Minutes, time.Seconds); + } + #endregion + + private void MuteButton_Click(object sender, RoutedEventArgs e) + { + mediaElement.IsMuted = (bool)muteButton.IsChecked; + } + + #region fullscreen mode + + private void FullScreenButton_Click(object sender, RoutedEventArgs e) + { + var content = Application.Current.Host.Content; + content.IsFullScreen = !content.IsFullScreen; + } + + private void Content_FullScreenChanged(object sender, EventArgs e) + { + UpdateVideoSize(); + } + + private void UpdateVideoSize() + { + if (App.Current.Host.Content.IsFullScreen) + { + // mediaElement takes all available space + VideoRow.Height = new GridLength(1, GridUnitType.Star); + VideoColumn.Width = new GridLength(1, GridUnitType.Star); + } + else + { + // mediaElement is only as big as the source video + VideoRow.Height = new GridLength(1, GridUnitType.Auto); + VideoColumn.Width = new GridLength(1, GridUnitType.Auto); + } + } + + #endregion + } +} \ No newline at end of file diff --git a/src/YalpClients/WebClient/Properties/AppManifest.xml b/src/YalpClients/WebClient/Properties/AppManifest.xml new file mode 100644 index 0000000..2e175fc --- /dev/null +++ b/src/YalpClients/WebClient/Properties/AppManifest.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/src/YalpClients/WebClient/Properties/AssemblyInfo.cs b/src/YalpClients/WebClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a7710f2 --- /dev/null +++ b/src/YalpClients/WebClient/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VideoPlayer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("MSIT")] +[assembly: AssemblyProduct("VideoPlayer")] +[assembly: AssemblyCopyright("Copyright © MSIT 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("35c726b0-7859-4c8e-a45c-81dc889f321e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/YalpClients/WebClient/VideoPlayer.csproj b/src/YalpClients/WebClient/VideoPlayer.csproj new file mode 100644 index 0000000..5e6c3f4 --- /dev/null +++ b/src/YalpClients/WebClient/VideoPlayer.csproj @@ -0,0 +1,103 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {9254F122-1734-4DEC-9859-49C16D114EBA} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + VideoPlayer + VideoPlayer + v3.5 + true + + + true + true + VideoPlayer.xap + Properties\AppManifest.xml + VideoPlayer.App + TestPage.html + true + true + false + true + + + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + + + + + + + + + + + + + + App.xaml + + + MainPage.xaml + + + + + + Designer + MSBuild:MarkupCompilePass1 + + + Designer + MSBuild:MarkupCompilePass1 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/YalpClients/WebClient/VideoPlayer.csproj.user b/src/YalpClients/WebClient/VideoPlayer.csproj.user new file mode 100644 index 0000000..47ceb7f --- /dev/null +++ b/src/YalpClients/WebClient/VideoPlayer.csproj.user @@ -0,0 +1,28 @@ + + + + + + + + DynamicPage + True + False + False + + + + + + + + + True + + + True + + + + + \ No newline at end of file diff --git a/src/YalpClients/WebClient/VideoPlayer.sln b/src/YalpClients/WebClient/VideoPlayer.sln new file mode 100644 index 0000000..9ef3f22 --- /dev/null +++ b/src/YalpClients/WebClient/VideoPlayer.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Web Developer Express 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoPlayer", "VideoPlayer.csproj", "{9254F122-1734-4DEC-9859-49C16D114EBA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9254F122-1734-4DEC-9859-49C16D114EBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9254F122-1734-4DEC-9859-49C16D114EBA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9254F122-1734-4DEC-9859-49C16D114EBA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9254F122-1734-4DEC-9859-49C16D114EBA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal -- cgit v1.2.3