public void PlayVideo(string path) { MediaElement player = new MediaElement(); player.Source = new Uri(path); player.AutoPlay = true; player.Play(); }
public enemyMissile(double left, double top) { // use this to create the missile on the fly. // calling function is going to supply the // X Y Coordinate to create at. // set up a rectangle // fill in the values - background, picture, StackPanel panel = new StackPanel(); Rectangle missileRect = new Rectangle(); missileRect.Height = 3; missileRect.Width = 12; missileRect.Fill = new SolidColorBrush(Colors.Black ); missileRect.Stroke = new SolidColorBrush(Colors.Yellow); missileRect.RadiusX = 1; missileRect.RadiusY = 1; panel.Children.Add(missileRect); MediaElement me = new MediaElement(); me.Source = new Uri("/laser.mp3", UriKind.Relative); panel.Children.Add(me); this.Content = panel; Canvas.SetTop(this, top); Canvas.SetLeft(this, left); me.Play(); }
public static Duration GetDuration(string fileName) { Duration naturalDuration = Duration.Automatic; Window w = new Window { Content = _videoElement = new MediaElement() { IsMuted = true }, IsHitTestVisible = false, Width = 0, Height = 0, WindowStyle = WindowStyle.None, ShowInTaskbar = false, ShowActivated = false }; _videoElement.MediaOpened += (sender, args) => { naturalDuration = _videoElement.NaturalDuration; _videoElement.Close(); w.Close(); }; _videoElement.LoadedBehavior = MediaState.Manual; _videoElement.UnloadedBehavior = MediaState.Manual; _videoElement.Source = new Uri(fileName); _videoElement.Play(); w.ShowDialog(); return naturalDuration; }
/// Starts the Audio/Video. public void Play() { if (player.Source != null) { player.Play(); } }
internal void Play(float volume) { //Creating and setting source within constructor starts //playing song immediately. song = new MediaElement(); song.MediaEnded += new RoutedEventHandler(song_MediaEnded); _graphics.Root.Children.Add(song); song.SetSource(resourceInfo.Stream); song.Volume = volume; song.Play(); }
private void TagVisualization3_Loaded(object sender, RoutedEventArgs e) { //TODO: customize TagVisualization3's UI based on this.VisualizedTag here base.OnInitialized(e); // Query the registry to find out where the sample media is stored. const string shellKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Folders"; string videosPath = (string)Microsoft.Win32.Registry.GetValue(shellKey, "CommonVideo", null) + @"\Sample Videos"; // The name of the video. string targetVideo = @"C:\Users\hcilab\Desktop\Polina\CS320HW2Media\greece.mp4"; // string targetVideo = @"Wildlife.wmv"; // Create a ScatterViewItem control and add it to the Items collection. ScatterViewItem item = new ScatterViewItem(); videoScatter.Items.Add(item); // Create a MediaElement object. MediaElement video = new MediaElement(); video.LoadedBehavior = MediaState.Manual; video.UnloadedBehavior = MediaState.Manual; // The media dimensions are not available until the MediaOpened event. video.MediaOpened += delegate { // Size the ScatterViewItem control according to the video size. item.Height = video.NaturalVideoHeight / 2; item.Width = video.NaturalVideoWidth / 2; }; // Set the Content to the video. item.Content = video; // Get the video if it exists. if (System.IO.File.Exists(targetVideo)) { video.Source = new Uri(targetVideo); video.Play(); } else { item.Content = "Video not found"; } }
// constructor public Game(UniformGrid g, Label label, StackPanel panel) { // TODO grid = g; titleLabel = label; stackPanel = panel; soundElement = InitializeMediaElement(); stackPanel.Children.Add(soundElement); soundElement.Play(); board = new Tile[grid.Rows, grid.Columns]; CreateBoard(); AddToGrid(); }
public LADSVideoBubble(String filename, double width, double height) { _filename = filename; _video = new MediaElement(); _controls = new VideoItem(); _sliderTimer = new DispatcherTimer(); _preferredSize = new Size(width, height); _layoutRoot = new Grid(); _video.MediaOpened += new RoutedEventHandler(video_MediaOpened); _video.MediaEnded += new RoutedEventHandler(video_MediaEnded); _video.ScrubbingEnabled = true; _video.LoadedBehavior = MediaState.Manual; _video.Source = new Uri(_filename, UriKind.RelativeOrAbsolute); //fire the MediaOpened event _video.Play(); _video.Pause(); _controls.HorizontalAlignment = HorizontalAlignment.Center; _controls.VerticalAlignment = VerticalAlignment.Center; _controls.Hide(); _controls.playButton.Click += new RoutedEventHandler(playButton_Click); _controls.stopButton.Click += new RoutedEventHandler(stopButton_Click); _controls.videoSlider.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(videoSlider_PreviewMouseLeftButtonDown); _controls.videoSlider.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(videoSlider_PreviewMouseLeftButtonUp); _controls.videoSlider.PreviewTouchDown += new System.EventHandler<TouchEventArgs>(videoSlider_PreviewTouchDown); _controls.videoSlider.PreviewTouchUp += new System.EventHandler<TouchEventArgs>(videoSlider_PreviewTouchUp); _controls.videoSlider.IsMoveToPointEnabled = false; _controls.videoSlider.SmallChange = 0; _controls.videoSlider.LargeChange = 0; _sliderTimer.Interval = new TimeSpan(0, 0, 0, 0, SLIDER_TIMER_RESOLUTION); _sliderTimer.Tick += new EventHandler(sliderTimer_Tick); _layoutRoot.RowDefinitions.Add(new RowDefinition()); _layoutRoot.RowDefinitions.Add(new RowDefinition()); _layoutRoot.RowDefinitions[1].Height = new GridLength(50); Grid.SetRow(_controls, 1); Grid.SetRow(_video, 0); _layoutRoot.Children.Add(_video); this.AddChild(_layoutRoot); //this.MouseEnter += new MouseEventHandler(VideoBubble_MouseEnter); //this.MouseLeave += new MouseEventHandler(VideoBubble_MouseLeave); this.SizeChanged += new SizeChangedEventHandler(LADSVideoBubble_SizeChanged); }
async void MediaPlayerCurrentPlay_Exception01_OK() { MediaPlayer.Current.Init(this); System.Windows.Controls.MediaElement Player = (System.Windows.Controls.MediaElement)ZPF.Media.MediaPlayer.Current.Player; try { Player.Source = new Uri("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3"); Player.Play(); } catch { // shit happens }; }
public static void PlayMedia(MediaElement mediaElement, MediaSource mediaSource) { try { if (mediaSource != null && mediaSource.Uri != null) { mediaElement.Stop(); mediaElement.Source = mediaSource.Uri; mediaElement.Play(); } } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "ManagerConsole.Helper.MediaManager:.\r\n{0}", ex.ToString()); } }
public static void PlayMedia(MediaElement mediaElement, string soundPath) { try { if (!string.IsNullOrEmpty(soundPath)) { Uri path = new Uri(soundPath, UriKind.Absolute); mediaElement.Stop(); mediaElement.Source = path; mediaElement.Play(); } } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "ManagerConsole.Helper.MediaManager:.\r\n{0}", ex.ToString()); } }
// Constructor takes a list of heroes, bgm, and titleScreen public MainWindow(Hero[] h, MediaElement song, Window create) { music = song; main = create; music.Source = new Uri("../../Menu.wav", UriKind.Relative); music.Play(); InitializeComponent(); //Sets the level/campus building's hoverOver statusmain = title; buildingSetUp(); //Apply all five buttons to the MouseLeave event handler //When a the mouse leaves one of the five character buttons the button should be set to hidden btnCharacter1.MouseLeave += character_MouseLeave; btnCharacter2.MouseLeave += character_MouseLeave; btnCharacter3.MouseLeave += character_MouseLeave; btnCharacter4.MouseLeave += character_MouseLeave; btnCharacter5.MouseLeave += character_MouseLeave; //Gives setOfHeroes array with passed array of Characters for (int i = 0; i < h.Length; i++) { setOfHeroes[i] = h[i]; } // places the heroes boardgame picture on the map. character1image.Source = setOfHeroes[0].CharacterPicture; character2image.Source = setOfHeroes[1].CharacterPicture; character3image.Source = setOfHeroes[2].CharacterPicture; character4image.Source = setOfHeroes[3].CharacterPicture; character5image.Source = setOfHeroes[4].CharacterPicture; if (music.IsMuted) { Style red = Sound_Off_Button.Style; // holds the red button style from the off button. Style black = Sound_On_Button.Style; // holds the blank button style from the on button. // swaps color styles with on and off. Sound_On_Button.Style = red; Sound_Off_Button.Style = black; } }
public static void playForDuration(Canvas parent, String filename, TimeSpan startPosition, TimeSpan duration) { MediaElement songMediaElement = new MediaElement(); parent.Children.Add(songMediaElement); songMediaElement.LoadedBehavior = MediaState.Manual; songMediaElement.Volume = 100; songMediaElement.Source = new Uri(@"" + filename, UriKind.RelativeOrAbsolute); var dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler((object sender, EventArgs e) => { songMediaElement.Stop(); (sender as DispatcherTimer).Stop(); parent.Children.Remove(songMediaElement); }); dispatcherTimer.Interval = duration; songMediaElement.Position = startPosition; songMediaElement.Play(); dispatcherTimer.Start(); }
public static void PlayMedia(MediaElement mediaElement, TimeSpan start, TimeSpan length, bool muted) { mediaElement.Stop(); mediaElement.Position = start; mediaElement.IsMuted = muted; Console.WriteLine("Playing video at {0}", start); mediaElement.Play(); DispatcherTimer timer = null; n++; int x = n; timer = new DispatcherTimer(length, DispatcherPriority.Send, (_s, _e) => { if (x == n) { mediaElement.Pause(); timer.Stop(); } }, mediaElement.Dispatcher); }
public void OpenMedia(Media item) { this.Item = item; TitleText.Text = Item.Title; TitleText.ToolTip = Item.Title; player = new MediaElement(); player.LoadedBehavior = MediaState.Manual; player.UnloadedBehavior = MediaState.Manual; player.MediaEnded += player_MediaEnded; player.IsMuted = true; player.Source = new Uri(Settings.NaturalGroundingFolder + Item.FileName); player.Position = TimeSpan.FromSeconds(Item.StartPos.HasValue ? Item.StartPos.Value : 0); player.Play(); viewer = ImageViewerWindow.Instance(player); viewer.Closed += viewer_Closed; positionTimer = new DispatcherTimer(); positionTimer.Interval = TimeSpan.FromSeconds(1); positionTimer.Tick += positionTimer_Tick; positionTimer.Start(); }
/// <summary> /// Creates a native Windows Phone MediaElement and immediatly starts playback. /// </summary> /// <param name="videoUrl">URL to the vidoe (from Windows Phone's point of view)</param> /// <param name="tapSkipsVideo">If true, a tap will stop & remove the Video playback</param> private static void PlayVideoFullscreenOnUIThread(string videoUrl, bool tapSkipsVideo) { #if WINDOWS_PHONE var frame = Application.Current.RootVisual as PhoneApplicationFrame; var currentPage = frame.Content as PhoneApplicationPage; DrawingSurfaceBackgroundGrid drawingSurfaceBackgroundElement = (DrawingSurfaceBackgroundGrid)currentPage.FindName("DrawingSurfaceBackground"); MediaElement videoPlayBackElement = new MediaElement(); videoPlayBackElement.Height = Double.NaN; videoPlayBackElement.Width = Double.NaN; videoPlayBackElement.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; videoPlayBackElement.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; videoPlayBackElement.Stretch = System.Windows.Media.Stretch.UniformToFill; videoPlayBackElement.Source = new Uri(videoUrl, UriKind.RelativeOrAbsolute); if (tapSkipsVideo) { videoPlayBackElement.Tap += delegate { drawingSurfaceBackgroundElement.Children.Remove(videoPlayBackElement); }; } drawingSurfaceBackgroundElement.Children.Add(videoPlayBackElement); videoPlayBackElement.Play(); #endif }
public void TestDetached () { int media_opened_counter = 0; int media_ended_counter = 0; int media_failed_counter = 0; int media_buffering_progress_counter = 0; int media_download_progress_counter = 0; int media_state_changed_counter = 0; MediaElement mel = new MediaElement (); TestPanel.Children.Add (mel); mel.BufferingProgressChanged += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) { Debug.WriteLine ("BufferingProgressChanged"); media_buffering_progress_counter++; }); mel.CurrentStateChanged += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) { Debug.WriteLine ("CurrentStateChanged"); media_state_changed_counter++; }); mel.DownloadProgressChanged += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) { Debug.WriteLine ("DownloadProgressChanged"); media_download_progress_counter++; }); mel.MediaEnded += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) { Debug.WriteLine ("MediaEnded"); media_ended_counter++; }); mel.MediaFailed += new EventHandler<ExceptionRoutedEventArgs> (delegate (object sender, ExceptionRoutedEventArgs e) { Debug.WriteLine ("MediaFailed"); media_failed_counter++; }); mel.MediaOpened += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) { Debug.WriteLine ("MediaOpened"); media_opened_counter++; }); mel.Source = new Uri ("/moon-unit;component/timecode-long-with-audio.wmv", UriKind.Relative); // set all properties to non-defaults, to check which ones are reset mel.AutoPlay = false; mel.Balance = 0.7; mel.BufferingTime = TimeSpan.FromSeconds (3.0); mel.IsMuted = true; mel.Volume = 0.33; // wait until media has been opened EnqueueConditional (() => media_opened_counter >= 1); // check initial values Enqueue (delegate () { Assert.AreEqual (0.0, mel.Position.TotalMilliseconds, "Initial - Position"); }); // play Enqueue (delegate () { mel.Play (); }); // wait until the media element is playing and has played 1 second EnqueueConditional (() => mel.Position.TotalMilliseconds > 1.0); // assert attached values Enqueue (delegate () { Assert.AreEqual (1, media_opened_counter, "Attached - MediaOpenedEvent"); Assert.AreEqual (0, media_ended_counter, "Attached - MediaEndedEvent"); Assert.AreEqual (0, media_failed_counter, "Attached - MediaFailedEvent"); Assert.IsGreater (0, media_buffering_progress_counter, "Attached - BufferingProgressChangedEvent"); Assert.IsGreater (0, media_download_progress_counter, "Attached - DownloadProgressChangedEvent"); Assert.IsGreater (0, media_state_changed_counter, "Attached - CurrentStateChangedEvent"); Assert.AreEqual (false, mel.AutoPlay, "Attached - AutoPlay"); Assert.AreEqualWithDelta (0.7, mel.Balance, 0.0001, "Attached - Balance"); Assert.AreEqual (1.0, mel.BufferingProgress, "Attached - BufferingProgress"); Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Attached - BufferingTime"); Assert.AreEqual (true, mel.CanPause, "Attached - CanPause"); Assert.AreEqual (true, mel.CanSeek, "Attached - CanSeek"); Assert.AreEqual (MediaElementState.Playing, mel.CurrentState, "Attached - CurrentState"); Assert.AreEqual (true, mel.IsMuted, "Attached - IsMuted"); Assert.AreEqual (30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Attached - NaturalDuration"); Assert.IsGreater (1.0, mel.Position.TotalMilliseconds, "Attached - Position"); Assert.AreEqualWithDelta (0.33, mel.Volume, 0.0001, "Attached - Volume"); }); // detach Enqueue (delegate () { media_opened_counter = 0; media_ended_counter = 0; media_failed_counter = 0; media_buffering_progress_counter = 0; media_download_progress_counter = 0; media_state_changed_counter = 0; TestPanel.Children.Clear (); // check what changed immediately Assert.AreEqual (0, media_opened_counter, "Detached (immediately) - MediaOpenedEvent"); Assert.AreEqual (0, media_ended_counter, "Detached (immediately) - MediaEndedEvent"); Assert.AreEqual (0, media_failed_counter, "Detached (immediately) - MediaFailedEvent"); Assert.AreEqual (0, media_buffering_progress_counter, "Detached (immediately) - BufferingProgressChangedEvent"); Assert.AreEqual (0, media_download_progress_counter, "Detached (immediately) - DownloadProgressChangedEvent"); Assert.AreEqual (0, media_state_changed_counter, "Detached (immediately) - CurrentStateChangedEvent"); Assert.AreEqual (false, mel.AutoPlay, "Detached (immediately) - AutoPlay"); Assert.AreEqualWithDelta (0.7, mel.Balance, 0.0001, "Detached (immediately) - Balance"); Assert.AreEqual (0.0, mel.BufferingProgress, "Detached (immediately) - BufferingProgress"); Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Detached (immediately) - BufferingTime"); Assert.AreEqual (false, mel.CanPause, "Detached (immediately) - CanPause"); Assert.AreEqual (false, mel.CanSeek, "Detached (immediately) - CanSeek"); Assert.AreEqual (MediaElementState.Playing, mel.CurrentState, "Detached (immediately) - CurrentState"); Assert.AreEqual (true, mel.IsMuted, "Detached (immediately) - IsMuted"); Assert.AreEqual (0.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Detached (immediately) - NaturalDuration"); Assert.AreEqual (0.0, mel.Position.TotalMilliseconds, "Detached (immediately) - Position"); Assert.AreEqualWithDelta (0.33, mel.Volume, 0.0001, "Detached (immediately) - Volume"); }); // wait a bit EnqueueSleep (100); // check detached values Enqueue (delegate () { Assert.AreEqual (0, media_opened_counter, "Detached - MediaOpenedEvent"); Assert.AreEqual (0, media_ended_counter, "Detached - MediaEndedEvent"); Assert.AreEqual (0, media_failed_counter, "Detached - MediaFailedEvent"); Assert.AreEqual (0, media_buffering_progress_counter, "Detached - BufferingProgressChangedEvent"); Assert.AreEqual (0, media_download_progress_counter, "Detached - DownloadProgressChangedEvent"); Assert.AreEqual (0, media_state_changed_counter, "Detached - CurrentStateChangedEvent"); Assert.AreEqual (false, mel.AutoPlay, "Detached - AutoPlay"); Assert.AreEqualWithDelta (0.7, mel.Balance, 0.0001, "Detached - Balance"); Assert.AreEqual (0.0, mel.BufferingProgress, "Detached - BufferingProgress"); Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Detached - BufferingTime"); Assert.AreEqual (false, mel.CanPause, "Detached - CanPause"); Assert.AreEqual (false, mel.CanSeek, "Detached - CanSeek"); Assert.AreEqual (MediaElementState.Playing, mel.CurrentState, "Detached - CurrentState"); Assert.AreEqual (true, mel.IsMuted, "Detached - IsMuted"); Assert.AreEqual (0.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Detached - NaturalDuration"); Assert.AreEqual (0.0, mel.Position.TotalMilliseconds, "Detached - Position"); Assert.AreEqualWithDelta (0.33, mel.Volume, 0.0001, "Detached - Volume"); }); // reattach Enqueue (delegate () { TestPanel.Children.Add (mel); // check which properties changed immediately Assert.AreEqual (0, media_opened_counter, "Reattached (immediately) - MediaOpenedEvent"); Assert.AreEqual (0, media_ended_counter, "Reattached (immediately) - MediaEndedEvent"); Assert.AreEqual (0, media_failed_counter, "Reattached (immediately) - MediaFailedEvent"); Assert.AreEqual (0, media_buffering_progress_counter, "Reattached (immediately) - BufferingProgressChangedEvent"); Assert.AreEqual (0, media_download_progress_counter, "Reattached (immediately) - DownloadProgressChangedEvent"); Assert.AreEqual (0, media_state_changed_counter, "Reattached (immediately) - CurrentStateChangedEvent"); Assert.AreEqual (false, mel.AutoPlay, "Reattached (immediately) - AutoPlay"); Assert.AreEqualWithDelta (0.7, mel.Balance, 0.001, "Reattached (immediately) - Balance"); Assert.AreEqual (1.0, mel.BufferingProgress, "Reattached (immediately) - BufferingProgress"); Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Reattached (immediately) - BufferingTime"); Assert.AreEqual (true, mel.CanPause, "Reattached (immediately) - CanPause"); Assert.AreEqual (true, mel.CanSeek, "Reattached (immediately) - CanSeek"); Assert.IsTrue (mel.CurrentState == MediaElementState.Opening || mel.CurrentState == MediaElementState.Playing, "Reattached (immediately) - CurrentState"); Assert.AreEqual (true, mel.IsMuted, "Reattached (immediately) - IsMuted"); Assert.AreEqual (0.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Reattached (immediately) - NaturalDuration"); Assert.AreEqual (0.0, mel.Position.TotalMilliseconds, "Reattached (immediately) - Position"); Assert.AreEqualWithDelta (0.33, mel.Volume, 0.0001, "Reattached (immediately) - Volume"); }); // wait a bit EnqueueSleep (200); EnqueueConditional (() => media_opened_counter >= 1); Enqueue (delegate () { Assert.AreEqual (1, media_opened_counter, "Reattached A - MediaOpenedEvent"); Assert.AreEqual (0, media_ended_counter, "Reattached A - MediaEndedEvent"); Assert.AreEqual (0, media_failed_counter, "Reattached A - MediaFailedEvent"); Assert.IsGreater (0, media_buffering_progress_counter, "Reattached A - BufferingProgressChangedEvent"); Assert.IsGreater (0, media_download_progress_counter, "Reattached A - DownloadProgressChangedEvent"); Assert.IsGreater (0, media_state_changed_counter, "Reattached A - CurrentStateChangedEvent"); Assert.AreEqual (false, mel.AutoPlay, "Reattached A - AutoPlay"); Assert.AreEqualWithDelta (0.7, mel.Balance, 0.001, "Reattached A - Balance"); Assert.AreEqual (1.0, mel.BufferingProgress, "Reattached A - BufferingProgress"); Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Reattached A - BufferingTime"); Assert.AreEqual (true, mel.CanPause, "Reattached A - CanPause"); Assert.AreEqual (true, mel.CanSeek, "Reattached A - CanSeek"); Assert.AreEqual (MediaElementState.Paused, mel.CurrentState, "Reattached A - CurrentState"); Assert.AreEqual (true, mel.IsMuted, "Reattached A - IsMuted"); Assert.AreEqual (30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Reattached A - NaturalDuration"); Assert.AreEqual (0.0, mel.Position.TotalMilliseconds, "Reattached A - Position"); Assert.AreEqualWithDelta (0.33, mel.Volume, 0.001, "Reattached A - Volume"); }); Enqueue (delegate () { mel.Play (); }); // wait until 0.1s have been played. This is to check that when we start playing again // we start at the beginning, not the position when the ME was detached. EnqueueConditional (() => mel.Position.TotalMilliseconds > 100); Enqueue (delegate () { Assert.AreEqual (1, media_opened_counter, "Reattached B - MediaOpenedEvent"); Assert.AreEqual (0, media_ended_counter, "Reattached B - MediaEndedEvent"); Assert.AreEqual (0, media_failed_counter, "Reattached B - MediaFailedEvent"); Assert.IsGreater (0, media_buffering_progress_counter, "Reattached B - BufferingProgressChangedEvent"); Assert.IsGreater (0, media_download_progress_counter, "Reattached B - DownloadProgressChangedEvent"); Assert.IsGreater (0, media_state_changed_counter, "Reattached B - CurrentStateChangedEvent"); Assert.AreEqual (false, mel.AutoPlay, "Reattached B - AutoPlay"); Assert.AreEqualWithDelta (0.7, mel.Balance, 0.001, "Reattached B - Balance"); Assert.AreEqual (1.0, mel.BufferingProgress, "Reattached B - BufferingProgress"); Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Reattached B - BufferingTime"); Assert.AreEqual (true, mel.CanPause, "Reattached B - CanPause"); Assert.AreEqual (true, mel.CanSeek, "Reattached B - CanSeek"); Assert.AreEqual (MediaElementState.Playing, mel.CurrentState, "Reattached B - CurrentState"); Assert.AreEqual (true, mel.IsMuted, "Reattached B - IsMuted"); Assert.AreEqual (30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Reattached B - NaturalDuration"); Assert.IsBetween (0.100, 0.9, mel.Position.TotalSeconds, "Reattached B - Position"); Assert.AreEqualWithDelta (0.33, mel.Volume, 0.001, "Reattached B - Volume"); }); // detach with AutoPlay = true Enqueue (delegate () { mel.AutoPlay = true; TestPanel.Children.Clear (); }); // reattach Enqueue (delegate () { TestPanel.Children.Add (mel); }); // wait until we've started playing again EnqueueConditional (() => mel.Position.TotalMilliseconds > 0); EnqueueTestComplete (); }
/// <summary> /// Zoom video, création de la progress bar, du "bouton" stop, des étoiles pleines et vides. /// </summary> /// <param name="sender">Video</param> /// <param name="e">Evenement</param> private void zoomVideo(object sender, MouseButtonEventArgs e) { if ((savingVideo == false)&&(clickLimit==false)) { zoom = true; maintenance.stopAllVideos(); fade = new Canvas(); fade.Background = Brushes.Black; Grid.SetRowSpan(fade, 4); Grid.SetColumnSpan(fade, 4); fade.Opacity = 0.50; gridMain.Children.Add(fade); TimeSpan videoSize; canvasHit = sender as Canvas; String[] nameNumber = canvasHit.Name.Split('c', '_'); MediaElement video = videoRetriever(nameNumber[1], nameNumber[2]); int videoNumber = ((Convert.ToInt32(nameNumber[1])) * 4) + (Convert.ToInt32(nameNumber[2])); Uri uriZoom = video.Source; zoomedVideo = new MediaElement(); Grid.SetRowSpan(zoomedVideo, 2); Grid.SetColumnSpan(zoomedVideo, 2); Grid.SetRow(zoomedVideo, 1); Grid.SetColumn(zoomedVideo, 1); zoomedVideo.Stretch = Stretch.Fill; zoomedVideo.UnloadedBehavior = MediaState.Manual; zoomedVideo.LoadedBehavior = MediaState.Manual; zoomedVideo.MediaEnded += mediaEnded; zoomedVideo.Source = uriZoom; buttonStop = new Grid(); Canvas canvasStop = new Canvas(); canvasStop.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Images/cross.png"))); canvasStop.MouseLeftButtonDown += zoomedVideoStop_Click; buttonStop.Children.Add(canvasStop); buttonStop.Height = 100; buttonStop.Width = 100; buttonStop.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; buttonStop.VerticalAlignment = VerticalAlignment.Top; progressBar = new System.Windows.Controls.ProgressBar(); progressBar.Margin = new Thickness(0, 0, 0, 194); progressBar.Height = 30; progressBar.Background = Brushes.PaleTurquoise; progressBar.Foreground = Brushes.Blue; Grid.SetColumnSpan(progressBar, 2); Grid.SetColumn(progressBar, 1); Grid.SetRow(progressBar, 3); Grid.SetColumn(buttonStop, 2); Grid.SetRow(buttonStop, 1); favorites = new Grid(); favorites.Width = 100; favorites.VerticalAlignment = VerticalAlignment.Top; favorites.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; Grid.SetColumn(favorites, 1); Grid.SetRow(favorites, 1); Grid.SetRowSpan(favorites, 2); for(int i=0;i<maintenance.getFavorite(videoNumber);i++) { if (i < 3) { RowDefinition line = new RowDefinition(); line.Height = new GridLength(100); favorites.RowDefinitions.Add(line); Canvas canvas = new Canvas(); canvas.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Images/starfull.png"))); Grid.SetRow(canvas, i); favorites.Children.Add(canvas); } } if (maintenance.getFavorite(videoNumber)<3) { if (hasVoted == false) { RowDefinition line = new RowDefinition(); line.Height = new GridLength(100); favorites.RowDefinitions.Add(line); canvasFavorite = new Canvas(); canvasFavorite.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Images/starempty.png"))); Grid.SetRow(canvasFavorite, maintenance.getFavorite(videoNumber)); favorites.Children.Add(canvasFavorite); } } videoSize = TimeSpan.FromSeconds(15); gridMain.Children.Add(zoomedVideo); gridMain.Children.Add(buttonStop); gridMain.Children.Add(progressBar); gridMain.Children.Add(favorites); progressBar.Minimum = 0; progressBar.Maximum = videoSize.TotalSeconds; timer.Interval = TimeSpan.FromMilliseconds(20); timer.Tick += new EventHandler(progressTick); timer.Start(); zoomedVideo.Position = TimeSpan.FromSeconds(15); zoomedVideo.Play(); Console.WriteLine("Lecture de la vidéo zoomée : " + zoomedVideo.Source.ToString()); } }
void AudioPlayer_MediaOpened (object sender, EventArgs e) { MediaPlayer AudioPlayer = sender as MediaPlayer; Duration AudioDuration = AudioPlayer.NaturalDuration; Uri SourceUri = AudioPlayer.Source; AudioPlayer.Close (); MediaElement AudioElement = new MediaElement (); this.Content = AudioElement; AudioElement.Source = SourceUri; AudioElement.LoadedBehavior = MediaState.Manual; AudioElement.MediaEnded += new RoutedEventHandler (AudioElement_MediaEnded); TimeSpan DurationToStop = m_StopTime - DateTime.Now.AddSeconds (3).TimeOfDay; if (DurationToStop < TimeSpan.FromSeconds (0)) { m_RepeatPlayingTimer.Interval = TimeSpan.FromTicks (1); m_RepeatPlayingTimer.Start (); return; } TimeSpan AnimationTimeSpan; if (DurationToStop > AudioDuration.TimeSpan) { AnimationTimeSpan = AudioDuration.TimeSpan; SetAnimationParameter (m_AnimationStoryBoard, TimeSpan.FromTicks (0), AnimationTimeSpan, TimeSpan.FromTicks (0), AudioElement, new PropertyPath (MediaElement.VolumeProperty)); } else { AnimationTimeSpan = DurationToStop; TimeSpan UnchangedDuration = AnimationTimeSpan - m_FadingDuration; SetAnimationParameter (m_AnimationStoryBoard, TimeSpan.FromTicks (0), UnchangedDuration, m_FadingDuration, AudioElement, new PropertyPath (MediaElement.VolumeProperty)); m_EndBeforeMediaEndTimer = new DispatcherTimer(); m_EndBeforeMediaEndTimer.Interval = DurationToStop; m_EndBeforeMediaEndTimer.Tick += new EventHandler (m_AnimationStoryBoard_Completed); m_EndBeforeMediaEndTimer.Start (); } m_AnimationStoryBoard.FillBehavior = FillBehavior.HoldEnd; m_AnimationStoryBoard.Begin (this); m_AnimationStoryBoard.Completed += new EventHandler (m_AnimationStoryBoard_Completed); AudioElement.Play (); }
/// <summary> /// Shows screen saver by creating one instance of ScreenSaverWindow for each monitor. /// /// Note: uses WinForms's Screen class to get monitor info. /// </summary> internal void ShowScreensaver() { System.Windows.Point scale = Interop.GetVisualScale(); Debug.WriteLine(scale); fx = new GrayscaleEffect { Chrominance = App.Config.Chrominance, Negative = App.Config.Negative, LeaveBlack = App.Config.LeaveBlack }; //System.Windows.Forms.Screen primary = System.Windows.Forms.Screen.PrimaryScreen; //set volume and stretch method this.VideoElement = new MediaElement(); VideoElement.UnloadedBehavior = MediaState.Manual; VideoElement.Source = App.Config.Video; VideoElement.IsMuted = false; VideoElement.Volume = App.Config.Volume; VideoElement.Stretch = App.Config.Stretch; VideoElement.MediaEnded += new RoutedEventHandler(VideoElement_MediaEnded); VideoElement.MediaOpened += new RoutedEventHandler(VideoElement_MediaOpened); //creates window on every screens foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens) { ScreenSaverWindow window = new ScreenSaverWindow(new VisualBrush(VideoElement)); window.WindowStartupLocation = WindowStartupLocation.Manual; //covers entire monitor Debug.WriteLine(screen.Bounds); window.Left = screen.Bounds.Left / scale.X; window.Top = screen.Bounds.Top / scale.Y; window.Width = (screen.Bounds.Right - screen.Bounds.Left) / scale.X; window.Height = (screen.Bounds.Bottom - screen.Bounds.Top) / scale.Y; window.VideoBlock.Width = window.Width; window.VideoBlock.Height = window.Height; window.Show(); } VideoElement.Play(); }
private void PlayBuildStatusSoundIfEnabled(MediaElement soundElement) { soundElement.Volume = 1.0; soundElement.Position = new TimeSpan(0); soundElement.Play(); }
public AssociatedDocListBoxItem(String labeltext, String imageUri, String _scatteruri, ArtworkModeWindow lb, string description) { _helpers = new Helpers(); _description = description; scatteruri = _scatteruri; _lb = lb; opened = false; dp = new DockPanel(); this.Content = dp; //if image if (_helpers.IsImageFile(_scatteruri)) { image = new Image(); _helpers = new Helpers(); FileStream stream = new FileStream(imageUri, FileMode.Open); System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream); System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage); stream.Close(); wpfImage.SetCurrentValue(DockPanel.DockProperty, Dock.Left); wpfImage.SetCurrentValue(HeightProperty, 50.0); wpfImage.SetCurrentValue(WidthProperty, 50 * wpfImage.Source.Width / wpfImage.Source.Height); dp.Children.Add(wpfImage); label = new Label(); label.Content = labeltext; label.FontSize = 18; label.SetCurrentValue(DockPanel.DockProperty, Dock.Right); dp.Children.Add(label); this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch); this.PreviewMouseDown += new MouseButtonEventHandler(onTouch); lb.getAssociatedDocToolBar().Items.Add(this); } //equivalent for videos else if (_helpers.IsVideoFile(_scatteruri)) { if (_helpers.IsDirShowFile(_scatteruri)) //can easily create nice thumbnails of the video using DirectShow { image = new Image(); imageUri = System.IO.Path.GetFullPath(imageUri); int decrement = System.IO.Path.GetExtension(imageUri).Length; imageUri = imageUri.Remove(imageUri.Length - decrement, decrement); imageUri += ".bmp"; FileStream stream = new FileStream(imageUri, FileMode.Open); System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream); System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage); stream.Close(); wpfImage.SetCurrentValue(DockPanel.DockProperty, Dock.Left); wpfImage.SetCurrentValue(HeightProperty, 50.0); wpfImage.SetCurrentValue(WidthProperty, 50 * wpfImage.Source.Width / wpfImage.Source.Height); dp.Children.Add(wpfImage); label = new Label(); label.Content = labeltext; label.FontSize = 18; label.SetCurrentValue(DockPanel.DockProperty, Dock.Right); dp.Children.Add(label); this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch); this.PreviewMouseDown += new MouseButtonEventHandler(onTouch); lb.getAssociatedDocToolBar().Items.Add(this); } //Code for not actually creating thumbnails of videos, but instead creating paused, unplayable media elements to act as thumbnails else { MediaElement thumVid = new MediaElement(); thumVid.Source = new Uri(scatteruri, UriKind.RelativeOrAbsolute); thumVid.LoadedBehavior = MediaState.Manual; thumVid.ScrubbingEnabled = true; thumVid.Play(); thumVid.Pause(); thumVid.Position = new TimeSpan(0, 0, 0, 0); thumVid.SetCurrentValue(DockPanel.DockProperty, Dock.Left); thumVid.SetCurrentValue(HeightProperty, 50.0); thumVid.SetCurrentValue(WidthProperty, 50 * thumVid.Width / thumVid.Height); dp.Children.Add(thumVid); label = new Label(); label.Content = labeltext; label.FontSize = 18; label.SetCurrentValue(DockPanel.DockProperty, Dock.Right); dp.Children.Add(label); this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch); this.PreviewMouseDown += new MouseButtonEventHandler(onTouch); lb.getAssociatedDocToolBar().Items.Add(this); } } }
private void playNextItem() { lock (sound_lists) { if (current_list_id == -1) return; if (sound_lists[current_list_id] == null) return; } while ((current_list_item < current_list.count) && (current_list.streams[current_list_item] == null)) { current_list_item++; } try { int copy_index = current_list_item; int copy_count = current_list.count; int copy_list_id = current_list_id; System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { try { lock (sound_lists) { // re-create media element each time in order to avoid multiple subscribers to MediaEnded event mediaElement = new MediaElement(); FreeMapMainScreen.get().LayoutRoot.Children.Add(mediaElement); mediaElement.SetSource(current_list.streams[copy_index]); mediaElement.Volume = 1.0;//todomt (double)((double)sound_level / 100.0); mediaElement.MediaEnded += delegate { lock (sound_lists) { if (current_list != null && current_list.streams != null && current_list.streams[copy_index] != null) { current_list.streams[copy_index].Close(); } copy_index++; if (copy_index == copy_count) { closeCurrentList(); FreeMapMainScreen.get().LayoutRoot.Children.Remove(mediaElement); if ((current_list.flags & SoundList.SOUND_LIST_NO_FREE) == 0) { listFree(sound_lists[copy_list_id]); } sound_lists[copy_list_id] = null; current_list = null; playNextList(); } else { mediaElement.SetSource(current_list.streams[copy_index]); mediaElement.Volume = 1.0;//todomt (double)((double)sound_level / 100.0); mediaElement.Play(); } } }; try { mediaElement.Play(); } catch (Exception e) { Console.WriteLine(e); } } } catch (Exception e) { Logger.log("Exception: " + e); } }); } catch (Exception e) { Logger.log("Exception: " + e); closeCurrentList(); playNextList(); return; } }
private static void ActivateFlickerVideo(MediaElement flicker) { flicker.Visibility = Visibility.Visible; flicker.Play(); }
public void prepare() { if (path != null) { if (mediaElement == null) { mediaElement = new MediaElement(); MainPage.m_mainPage.LayoutRoot.Children.Add(mediaElement); mediaElement.MediaOpened += mediaElement_MediaOpened; mediaElement.MediaFailed += mediaElement_MediaFailed; mediaElement.MediaEnded += mediaElement_MediaEnded; if (mediaElement.Source == null) { mediaElement.Source = new Uri(path, UriKind.RelativeOrAbsolute); mediaElement.Play(); mediaElement.Pause(); } } timeLastPlayed = DateTime.Now; } }
public void LoadAllMusic() { TypeMusicList.Clear(); TypeSoundList.Clear(); foreach (var td in ThemeData) { if (td.Value.EndsWith(".wav")) { var sound = new SoundPlayer(GameParameters.Path + td.Value); sound.LoadAsync(); TypeSoundList.Add(td.Key, sound); } else if (td.Value.EndsWith(".mp3")) { var u = new Uri(GameParameters.Path + td.Value); var sound = new MediaElement(); sound.Source = u; sound.LoadedBehavior = MediaState.Manual; sound.Volume = 0; sound.Play(); sound.Stop(); sound.Volume = 0.8; TypeMusicList.Add(td.Key, sound); } } }
/// <summary> /// Load data inside the hotspot detail control, can be text or image. /// </summary> /// private void scatterItem_Loaded(object sender, RoutedEventArgs e) { firstTime = true; Name.Content = m_hotspotData.Name; //if (m_hotspotData.Type.ToLower().Contains("image")) //{ // MinX = 402; // MinY = 320; // BitmapImage img = new BitmapImage(); // String imgUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Images\\" + m_hotspotData.Description; // img.BeginInit(); // img.UriSource = new Uri(imgUri, UriKind.Absolute); // img.CacheOption = BitmapCacheOption.OnLoad; // img.EndInit(); // HotspotImage.Source = img; // HotspotImage.Visibility = Visibility.Visible; // HotspotImage.IsEnabled = true; // double maxWidth = 800.0; // if (img.PixelWidth > maxWidth) // { // HotspotImage.SetCurrentValue(HeightProperty, maxWidth * img.PixelHeight / img.PixelWidth); // HotspotImage.SetCurrentValue(WidthProperty, maxWidth); // } // else // { // HotspotImage.SetCurrentValue(HeightProperty, (double) img.PixelHeight); // HotspotImage.SetCurrentValue(WidthProperty, (double) img.PixelWidth); // } // this.SetCurrentValue(HeightProperty, HotspotImage.Height + 47.0); // this.SetCurrentValue(WidthProperty, HotspotImage.Width + 24.0); // hotspotCanvas.Width = HotspotImage.Width + 24.0; // hotspotCanvas.Height = HotspotImage.Height + 47.0; // this.Width = hotspotCanvas.Width; // this.Height = hotspotCanvas.Height; // HotspotTextBox.Visibility = Visibility.Hidden; // //textBoxScroll.Visibility = Visibility.Hidden; // VideoStackPanel.Visibility = Visibility.Collapsed; // AudioScroll.Visibility = Visibility.Hidden; //} if (m_hotspotData.Type.ToLower().Contains("text")) { HotspotTextBox.Text = m_hotspotData.Description; //HotspotTextBox.IsHitTestVisible = false; HotspotTextBox.Visibility = Visibility.Visible; //textBoxScroll.Visibility = Visibility.Visible; HotspotImage.Visibility = Visibility.Hidden; HotspotImage.IsEnabled = false; VideoStackPanel.Visibility = Visibility.Collapsed; AudioScroll.Visibility = Visibility.Hidden; this.CanScale = false; this.Width = 420; } else if (m_hotspotData.Type.ToLower().Contains("audio")) { Width = 300; Height = 200; hotspotCanvas.Width = Width - 8; hotspotCanvas.Height = Height - 8; VideoStackPanel.Visibility = Visibility.Collapsed; //textBoxScroll.Visibility = Visibility.Collapsed; //creates new audio myMediaElement = new MediaElement(); String newaudioUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Audios\\" + m_hotspotData.Description; myMediaElement.Source = new Uri(newaudioUri); AudioScroll.Children.Add(myMediaElement); myMediaElement.Width = VideoStackPanel.Width; myMediaElement.Height = VideoStackPanel.Height - 30; Name.Width = Width - (422 - 335); VideoStackPanel.Visibility = Visibility.Collapsed; videoCanvas.Visibility = Visibility.Collapsed; //textBoxScroll.Visibility = Visibility.Collapsed; HotspotTextBox.Visibility = Visibility.Hidden; myMediaElement.MediaOpened += new RoutedEventHandler(myMediaElement_MediaOpened); myMediaElement.MediaEnded += new RoutedEventHandler(myMediaElement_MediaEnded); //need to fill in method myMediaElement.LoadedBehavior = MediaState.Manual; String audioUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Audios\\" + m_hotspotData.Description; myMediaElement.Source = new Uri(audioUri); AudioScroll.Visibility = Visibility.Visible; timelineSlider.Visibility = Visibility.Visible; VideoStackPanel.Visibility = Visibility.Collapsed; AudioScroll.Width = hotspotCanvas.Width - 24; AudioScroll.Height = hotspotCanvas.Height + AudioTextbox.ActualHeight - 47; if (m_hotspotData.fileDescription == "") { AudioTextbox.Visibility = Visibility.Hidden; } else { AudioTextbox.Content = "Description: " + m_hotspotData.fileDescription; AudioTextbox.Width = hotspotCanvas.Width; } this.UpdateLayout(); AudioTextbox.Width = this.ActualWidth-8; hotspotCanvas.SetCurrentValue(HeightProperty, hotspotCanvas.Height + AudioTextbox.ActualHeight+40); this.SetCurrentValue(HeightProperty, hotspotCanvas.Height+8); //fire Media Opened in order to set the actual length myMediaElement.Play(); myMediaElement.Pause(); this.CanScale = false; PlayButton.Click += new RoutedEventHandler(PlayButton_Click); PauseButton.Click += new RoutedEventHandler(PauseButton_Click); StopButton.Click += new RoutedEventHandler(StopButton_Click); this.showAudioIcon(); _dragging = false; _sliderTimer = new System.Windows.Threading.DispatcherTimer(); timelineSlider.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(timelineSlider_PreviewMouseLeftButtonDown); timelineSlider.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(timelineSlider_PreviewMouseLeftButtonUp); timelineSlider.PreviewTouchDown += new System.EventHandler<TouchEventArgs>(timelineSlider_PreviewTouchDown); timelineSlider.PreviewTouchUp += new System.EventHandler<TouchEventArgs>(timelineSlider_PreviewTouchUp); timelineSlider.IsMoveToPointEnabled = false; timelineSlider.SmallChange = 0; timelineSlider.LargeChange = 0; _sliderTimer.Interval = new TimeSpan(0, 0, 0, 0, SLIDER_TIMER_RESOLUTION); _sliderTimer.Tick += new EventHandler(sliderTimer_Tick); _sliderTimer.Stop(); } else if (m_hotspotData.Type.ToLower().Contains("video")) { String videoUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Videos\\" + m_hotspotData.Description; videoElement = new MediaElement(); videoElement.Source = new Uri(videoUri); videoTimer = new DispatcherTimer(); videoTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); videoTimer.Tick += new EventHandler(videoTimer_Tick); videoElement.MediaOpened += new RoutedEventHandler(videoElement_MediaOpened); videoElement.MediaEnded += VideoElementDone; videoElement.LoadedBehavior = MediaState.Manual; videoElement.Play(); videoElement.Pause(); VideoStackPanel.Children.Insert(1,videoElement); //textBoxScroll.Visibility = Visibility.Collapsed; AudioScroll.Visibility = Visibility.Collapsed; hasVideo = true; Grid g = new Grid(); g.Height = 30; g.Width = 100; g.HorizontalAlignment = HorizontalAlignment.Left; Polygon p = new Polygon(); PointCollection ppoints = new PointCollection(); ppoints.Add(new System.Windows.Point(4, 5)); ppoints.Add(new System.Windows.Point(4, 26)); ppoints.Add(new System.Windows.Point(23, 14)); p.Points = ppoints; p.Fill = Brushes.Green; //p.Opacity = 1; p.Visibility = Visibility.Visible; p.Margin = new Thickness(0, 0, 0, 0); p.Stroke = Brushes.Black; p.StrokeThickness = 1; p.HorizontalAlignment = HorizontalAlignment.Left; p.VerticalAlignment = VerticalAlignment.Center; p.Height = 36; p.Width = 30; Polygon pause = new Polygon(); PointCollection pausepoints = new PointCollection(); pausepoints.Add(new System.Windows.Point(29, -1)); pausepoints.Add(new System.Windows.Point(29, 22)); pausepoints.Add(new System.Windows.Point(37, 22)); pausepoints.Add(new System.Windows.Point(37, -1)); pause.Points = pausepoints; pause.Fill = Brushes.Blue; //p.Opacity = 1; pause.Visibility = Visibility.Visible; pause.Margin = new Thickness(0, 0, 0, 0); pause.Stroke = Brushes.Black; pause.StrokeThickness = 1; pause.HorizontalAlignment = HorizontalAlignment.Left; pause.VerticalAlignment = VerticalAlignment.Center; Polygon pause2 = new Polygon(); PointCollection pausepoints2 = new PointCollection(); pausepoints2.Add(new System.Windows.Point(43, -1)); pausepoints2.Add(new System.Windows.Point(43, 22)); pausepoints2.Add(new System.Windows.Point(51, 22)); pausepoints2.Add(new System.Windows.Point(51, -1)); pause2.Points = pausepoints2; pause2.Fill = Brushes.Blue; //p.Opacity = 1; pause2.Visibility = Visibility.Visible; pause2.Margin = new Thickness(0, 0, 0, 0); pause2.Stroke = Brushes.Black; pause2.StrokeThickness = 1; pause2.HorizontalAlignment = HorizontalAlignment.Left; pause2.VerticalAlignment = VerticalAlignment.Center; g.Children.Add(p); g.Children.Add(pause); g.Children.Add(pause2); g.Visibility = Visibility.Visible; SurfacePlayButton.Content = g; HotspotTextBox.Visibility = Visibility.Hidden; Canvas.SetTop(VideoStackPanel, 35); if (m_hotspotData.fileDescription == "") { VideoText.Visibility = Visibility.Hidden; } else { VideoText.Content = "Description: " + m_hotspotData.fileDescription; } } else if((m_hotspotData.Type.ToLower().Contains("image"))) { sizeChanged = false; BitmapImage img = new BitmapImage(); String imgUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Images\\" + m_hotspotData.Description; img.BeginInit(); img.UriSource = new Uri(imgUri, UriKind.Absolute); img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); HotspotImageMix.Source = img; HotspotImageMix.Visibility = Visibility.Visible; HotspotImageMix.IsEnabled = true; double maxWidth = 600.0; if (img.PixelWidth > maxWidth) { HotspotImageMix.SetCurrentValue(HeightProperty, maxWidth * img.PixelHeight / img.PixelWidth); HotspotImageMix.SetCurrentValue(WidthProperty, maxWidth); } else { HotspotImageMix.SetCurrentValue(HeightProperty, (double)img.PixelHeight); HotspotImageMix.SetCurrentValue(WidthProperty, (double)img.PixelWidth); } if (m_hotspotData.fileDescription == "") { HotspotTextBoxMix.Visibility = Visibility.Hidden; } else { HotspotTextBoxMix.Content = "Description: "+m_hotspotData.fileDescription; HotspotTextBoxMix.Width = HotspotImageMix.Width; } this.UpdateLayout(); this.SetCurrentValue(HeightProperty, HotspotImageMix.Height + 10.0 + HotspotTextBoxMix.ActualHeight); this.SetCurrentValue(WidthProperty, HotspotImageMix.Width + 10.0); HotspotTextBox.Visibility = Visibility.Hidden; hotspotCanvas.Width = HotspotImageMix.Width; hotspotCanvas.Height = HotspotImageMix.Height + HotspotTextBoxMix.ActualHeight; //textBoxScroll.Visibility = Visibility.Visible; Mix.Visibility = Visibility.Visible; Canvas.SetZIndex(Mix, 100); this.UpdateLayout(); this.CanScale = true; Canvas.SetZIndex(closeButton, 100); //HotspotTextBox.Visibility = Visibility.Hidden; //textBoxScroll.Visibility = Visibility.Hidden; VideoStackPanel.Visibility = Visibility.Collapsed; AudioScroll.Visibility = Visibility.Hidden; // windowSize = new Size(this.Width, this.Height); } Double[] size = this.findImageSize(); screenPosX = (m_msi.GetZoomableCanvas.Scale * m_hotspotData.PositionX *size[0]) - m_msi.GetZoomableCanvas.Offset.X; screenPosY = (m_msi.GetZoomableCanvas.Scale * m_hotspotData.PositionY *size[1]) - m_msi.GetZoomableCanvas.Offset.Y; this.Center = new Point(screenPosX + this.Width/2.0, screenPosY + this.Height/2.0); sizeChanged = true; firstTime = false; }
public void wlacz_muzyke(MediaElement me, int ID_muzyka) { int index_ID = 0; for (int i = 0; i < ID.Length; i++) { if (ID[i] == ID_muzyka) { index_ID = i; break; } } me.Source = new Uri(adres_zrodlowy_film[index_ID], UriKind.Relative); me.LoadedBehavior = MediaState.Manual; me.UnloadedBehavior = MediaState.Stop; me.Play(); }
private Window Setup(Screen screen) { var minLeftScreen = Screen.AllScreens.Min(x => x.Bounds.Left) * -1; var minTopScreen = Screen.AllScreens.Min(x => x.Bounds.Top) * -1; _image = new Image() { Margin = new Thickness(0), Stretch = Stretch.UniformToFill }; //_video2 = new Unosquare.FFME.MediaElement //{ // LoadedBehavior = MediaState.Manual, // Margin = new Thickness(0), // Stretch = Stretch.UniformToFill //}; //_video2.MediaEnded += (s, e) => //{ // _video.Position = TimeSpan.FromSeconds(0); // _video.Play(); //}; //_video2.MediaOpened += (s, e) => //{ // _video.Play(); //}; //_video2.Loaded += (s, e) => //{ // _video.Play(); //}; _video = new System.Windows.Controls.MediaElement { LoadedBehavior = MediaState.Manual, Margin = new Thickness(0), Stretch = Stretch.UniformToFill }; _video.MediaEnded += (s, e) => { _video.Position = TimeSpan.FromSeconds(0); _video.Play(); }; _video.MediaOpened += (s, e) => { _video.Play(); }; _video.Loaded += (s, e) => { _video.Play(); }; var grid = new Grid(); grid.Children.Add(_image); grid.Children.Add(_video); _image.Visibility = Visibility.Hidden; _video.Visibility = Visibility.Hidden; return(new Window { Height = screen.Bounds.Height, Width = screen.Bounds.Width, WindowStyle = WindowStyle.None, Background = new SolidColorBrush(Colors.DarkSlateGray), ShowInTaskbar = false, //AllowsTransparency = false, ResizeMode = ResizeMode.NoResize, Left = screen.Bounds.Left + minLeftScreen, Top = screen.Bounds.Top + minTopScreen, Content = new Border { Background = new SolidColorBrush(Colors.Black), Margin = new Thickness(0), Child = grid }, }); }
/// <summary> /// Shows screen saver preview by creating one instance of ScreenSaverWindow. /// /// Note: uses WinForms's Screen class to get monitor info. /// </summary> internal void ShowPreview(String arg) { System.Windows.Point scale = Interop.GetVisualScale(); Debug.WriteLine(scale); fx = new GrayscaleEffect { Chrominance = App.Config.Chrominance, Negative = App.Config.Negative, LeaveBlack = App.Config.LeaveBlack }; //set volume and stretch method this.VideoElement = new MediaElement(); VideoElement.UnloadedBehavior = MediaState.Manual; VideoElement.Source = App.Config.Video; VideoElement.IsMuted = false; VideoElement.Volume = App.Config.Volume; VideoElement.Stretch = App.Config.Stretch; VideoElement.MediaEnded += new RoutedEventHandler(VideoElement_MediaEnded); VideoElement.MediaOpened += new RoutedEventHandler(VideoElement_MediaOpened); Int32 previewHandle = Convert.ToInt32(arg); IntPtr pPreviewHnd = new IntPtr(previewHandle); RECT lpRect = new RECT(); bool bGetRect = GetClientRect(pPreviewHnd, ref lpRect); this.winSaver = new ScreenSaverWindow(new VisualBrush(VideoElement)); HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams"); //set window properties sourceParams.Height = lpRect.Bottom - lpRect.Top; sourceParams.Width = lpRect.Right - lpRect.Left; sourceParams.ParentWindow = pPreviewHnd; sourceParams.WindowStyle = (int)(0x10000000 | 0x40000000 | 0x02000000); //set up preview winWPFContent = new HwndSource(sourceParams); winWPFContent.Disposed += new EventHandler(winWPFContent_Disposed); winWPFContent.RootVisual = winSaver.grid1; winSaver.Width = (lpRect.Right - lpRect.Left) / scale.X; winSaver.Height = (lpRect.Bottom - lpRect.Top) / scale.Y; winSaver.VideoBlock.Width = (lpRect.Right - lpRect.Left) / scale.X; winSaver.VideoBlock.Height = (lpRect.Right - lpRect.Left) / scale.X; //set a background //Note: Uses an arbitrary screen size to determine when to do this if (winSaver.Width <= 320 && winSaver.Height <= 240) { winSaver.DesktopBackground.Source = new BitmapImage(new Uri(Interop.GetDesktopWallpaper(), UriKind.Absolute)); winSaver.DesktopBackground.Stretch = Interop.GetWallpaperStretch(); } winSaver.isPreview = true; winSaver.Show(); VideoElement.Play(); }
/// <summary> /// Redemarrer les videos /// </summary> /// <param name="video">Mur video</param> public void videoRestart(MediaElement video) { video.Stop(); video.Play(); }
private void DisplayLoginScreen() { LoginWindow loginWindow = new LoginWindow(); MediaElement player = new MediaElement(); loginWindow.Owner = this; loginWindow.ShowDialog(); if (loginWindow.DialogResult.HasValue && loginWindow.DialogResult.Value) { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += (o, ea) => { Dispatcher.Invoke((Action)(() => player.Play())); GetSpreadsheet(loginWindow.service); Dispatcher.Invoke((Action)(() => PlayerDataGrid.ItemsSource = Players)); }; worker.RunWorkerCompleted += (o, ea) => { LoadingIndicator.IsBusy = false; FilterComboBox.SelectedIndex = 0; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(PlayerDataGrid.ItemsSource); view.Filter = WinsFilter; GetGamesPlayed(); }; InitializeInsultList(); Random random = new Random(); int randomNum = random.Next(InsultList.Count); LoadingIndicator.IsBusy = true; LoadingIndicator.BusyContent = InsultList[randomNum]; worker.RunWorkerAsync(); GetSound(randomNum, player); } else { Environment.Exit(1); } }
private void Window_Loaded (object sender, RoutedEventArgs e) { FirstTimeLoad = true; switch (m_NavigationType) { case NavigationWindowType.InternetNavigation: { bool PrintAllowed = false; if (!String.IsNullOrEmpty (m_PrintQueueName)) PrintAllowed = CheckForPrintability (StartupHTMLString); CreateCommonFrameGeometry (PrintAllowed); //Grid ScrollingGrid = m_XAMLHandling.CreateGrid (new int [] {90, 10}, new int [] {100}); //Grid_Root.Children.Add (ScrollingGrid); m_ScrollFrame = new ScrollViewer (); Grid_Root.Children.Add (m_ScrollFrame); Grid.SetColumn (Grid_Root, 0); Grid.SetRow (Grid_Root, 0); m_ScrollFrame.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden; m_ScrollFrame.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; if (System.Uri.IsWellFormedUriString (StartupHTMLString, UriKind.Absolute)) m_BrowserWindow.Source = new Uri (StartupHTMLString); m_BrowserWindow.Navigate (new Uri (StartupHTMLString)); break; } case NavigationWindowType.XAMLPage: { String VideoFileName = CVM.CommonValues.BUTTON_LINK_TYPE_MOVIE_FILE_NAME_PREFIX + StartupHTMLString + "\\" + StartupHTMLString + CVM.CommonValues.BUTTON_LINK_TYPE_MOVIE_FILE_NAME_POSTFIX; if (!File.Exists (VideoFileName)) { m_SecondsToBeAlive = 1; break; } CreateCommonFrameGeometry (false); MediaElement MovieControl = new MediaElement (); Grid_Root.Children.Add (MovieControl); Grid_Root.UpdateLayout (); MovieControl.Source = new Uri (VideoFileName); MovieControl.LoadedBehavior = MediaState.Manual; MovieControl.UnloadedBehavior = MediaState.Stop; MovieControl.MediaEnded += new RoutedEventHandler (MovieControl_MediaEnded); //MovieControl.Width = (m_CVM.VideoWidth * 100) / 80; //MovieControl.Height = (m_CVM.VideoHeight * 100) / 80; MovieControl.Play (); break; } case NavigationWindowType.SimpleText: { break; } } if (m_TimeToKeepAliveControl != null) { SetProgressBarAnimation (m_SecondsToBeAlive); } }