Esempio n. 1
0
 /// Stops the Audio/Video.
 public void Stop()
 {
     if (player.Source != null)
     {
         player.Stop();
     }
 }
 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());
     }
 }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     image = (System.Windows.Controls.Image)GetTemplateChild("Image");
     oldImage = (System.Windows.Controls.Image)GetTemplateChild("OldImage");
     NextImage = (Storyboard)GetTemplateChild("NextImage");
     Sound = (MediaElement)GetTemplateChild("Sound");
     if (image != null && oldImage != null && NextImage != null)
     {
         Initialize = true;
         Image = 1;
         if (!DesignerProperties.IsInDesignTool)
         {
             InitTimer();
             NextImage.Completed += new EventHandler(AnimationCompleted);
             if (Sound != null)
             {
                 Sound.Stop();
             }
         }
     }
 }
 /// <summary>
 /// Redemarrer les videos
 /// </summary>
 /// <param name="video">Mur video</param>
 public void videoRestart(MediaElement video)
 {
     video.Stop();
     video.Play();
 }
 /// <summary>
 /// Arreter la video desiree (pendant le zoom avec croix rouge)
 /// </summary>
 /// <param name="media"></param>
 public void stopVideo(MediaElement media)
 {
     media.Stop();
 }
Esempio n. 9
0
 private void StopMedia(MediaElement media)
 {
     media.Stop();
 }
Esempio n. 10
0
 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);
         }
     }
 }
Esempio n. 11
0
 private MediaElement InitializeMediaElement()
 {
     MediaElement element = new MediaElement();
     element.LoadedBehavior = MediaState.Manual;
     element.UnloadedBehavior = MediaState.Stop;
     element.MediaEnded += new System.Windows.RoutedEventHandler(
         (o, e) => element.Stop());
     element.Source = new System.Uri("Sounds/MineSweeper.mp3", UriKind.Relative);
     return element;
 }
        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)
            {

            }
        }
Esempio n. 13
0
    private RoutedEventHandler CurrentControlOnMediaOpened(MediaElement lastControl)
    {

        return delegate(object j, RoutedEventArgs y)
        {

            this.CurrentControl.Visibility = Visibility.Visible;

            DoubleAnimation animation = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromMilliseconds(1300.0)));

            DoubleAnimation animation2 = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromMilliseconds(1300.0)));

            animation.AutoReverse = false;

            animation2.AutoReverse = false;

            animation2.Completed += delegate(object f, EventArgs k)
            {

                lastControl.Stop();

                lastControl.Visibility = Visibility.Hidden;

            };

            animation.Completed += delegate(object f, EventArgs k)
            {

                lastControl.Stop();

                lastControl.Visibility = Visibility.Hidden;

            };

            lastControl.BeginAnimation(UIElement.OpacityProperty, animation2);

            this.CurrentControl.BeginAnimation(UIElement.OpacityProperty, animation);

        };

    }
Esempio n. 14
0
        protected override void OnPreviewKeyDown( KeyEventArgs e )
        {
            this.mainWindowViewModel.OnPreviewKeyDown( e );

            // konami code management.
            if ( _originalBackground == null )
            {
                _originalBackground = MainPanel.Background;
                _originalViewBox = DepthViewerPanel.Children[0];
            }
            string i = "UpUpDownDownLeftRightLeftRightBA";
            if ( e.Key.ToString() == "Up" && _konami != "Up" )
            {
                _konami = "";
            }
            _konami = ( _konami + e.Key.ToString() );
            // Debug.Print(konami)
            if ( ( _konami == i ) )
            {
                mainWindowViewModel.Konami = true;
                string fileName = "..\\..\\Resources\\mad_duck.jpg";
                System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage( new System.Uri( fileName, System.UriKind.Relative ) );
                System.Windows.Media.ImageBrush brush = new System.Windows.Media.ImageBrush();
                brush.ImageSource = image;
                MainPanel.Background = brush;

                Viewbox v = new Viewbox();
                MediaElement me = new MediaElement();
                fileName = "..\\..\\Resources\\Star Wars Ducks.mp4";
                me.Source = new System.Uri( fileName, System.UriKind.Relative );
                me.LoadedBehavior = MediaState.Manual;
                me.MediaEnded += new RoutedEventHandler( delegate( object s, RoutedEventArgs re ) { me.Stop(); me.Play(); } );
                me.Play();
                v.Child = me;
                DepthViewerPanel.Children.RemoveAt( 0 );
                DepthViewerPanel.Children.Add( v );
            }
            else if ( _konami.Length > i.Length )
            {
                mainWindowViewModel.Konami = false;
                MainPanel.Background = _originalBackground;
                DepthViewerPanel.Children.RemoveAt( 0 );
                DepthViewerPanel.Children.Add( _originalViewBox );
            }
        }