Skip to main content
Tweeted twitter.com/StackCodeReview/status/820033205738885124
Rollback to Revision 2
Source Link
t3chb0t
  • 44.7k
  • 9
  • 84
  • 191
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    /// <summary>
    /// New WPF Window
    ///#region </summary>Medias
    private Display _avc = new Display();
    /// <summary>
    /// Mp3 Player
    /// </summary>
    private MediaPlayer _raoulraoul = new MediaPlayer();
    
    private bool _videoIsPlaying;
    private bool _imageIsDisplaying;
    private bool _backgroundImageIsPlayiing;
    private bool _textIsDisplaying;
    private bool _musicIsPlaying;
    
    /// <summary>
    /// Video Url
    /// </summary>
    private readonly string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";#endregion

    ///#region <summary>Booleans
    ///private Videobool UrlvideoIsPlaying Accessors= false;
    ///private </summary>bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;
    
    /// <summary>#endregion

    ///#region Constructor
    ///& </summary>override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += HandleEsc;new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    /// <summary>
    /// Closes Program if Window closed
    /// </summary>
    /// <param name="e"></param>
    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion

    
    /// <summary>
    /// Button putting Text into next Window
    /// </summary>
    /// <param name="sender"></param>
    /// <param#region name="e"></param>Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    /// <summary>
    /// Media Opener
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            varstring fileExtentionstr = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (fileExtentionstr)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    _raoulraoul.Close();
                    _raoulraoul.Open(new Uri(openFileDialog.FileName));
                    _raoulraoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    /// <summary>
    /// Restart Media / Play Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!_musicIsPlayingmusicIsPlaying)
        {
            _raoulraoul.Play();
            _musicIsPlayingmusicIsPlaying = true;
        }
        if (_backgroundImageIsPlayiingbackgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (_videoIsPlayingvideoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Pause Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (_musicIsPlayingmusicIsPlaying)
        {
            _raoulraoul.Pause();
            _musicIsPlayingmusicIsPlaying = false;
        }
        if (_backgroundImageIsPlayiingbackgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (_videoIsPlayingvideoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
   #region ///ListBox <paramof name="e"></param>videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplayingimageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (_textIsDisplayingtextIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (_videoIsPlayingvideoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        _backgroundImageIsPlayiingbackgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplayingimageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (_textIsDisplayingtextIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (_videoIsPlayingvideoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        _backgroundImageIsPlayiingbackgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplayingimageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (_textIsDisplayingtextIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (_videoIsPlayingvideoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        _backgroundImageIsPlayiingbackgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplayingimageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (_textIsDisplayingtextIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (_videoIsPlayingvideoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        _backgroundImageIsPlayiingbackgroundImageIsPlayiing = true;
    }
    #endregion

    
    /// <summary>
    /// Tetris Theme
    /// </summary>
    /// <param name="sender"></param>
   #region ///ListBox <paramof name="e"></param>music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoulref raoul, @"tetris.mp3");
    }

    /// <summary>
    /// We are Number One - Lazy Town
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoulref raoul, @"wano.mp3");
    }

    /// <summary>
    /// Ultimate - Denzel Curry
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoulref raoul, @"ultimate.mp3");
    }

    /// <summary>
    /// CsGo theme Song
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoulref raoul, @"csgo.mp3");
    }
    
    /// <summary>#endregion
    /// Sets Medialement Url
    /// </summary>
    /// <param name="a"></param>
 #region Videos, Text ///and <paramSound name="url"></param>Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += BackgroundMediaElement_MediaEnded;new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start front Videos
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void PlayVideoHolo(ref Display displayx, string urla)
    {

        if (_imageIsDisplayingimageIsDisplaying)
        {
            HideImages(displayref x);
        }
        if (_textIsDisplayingtextIsDisplaying)
        {
            HideText(displayref x);
        }
        if (_backgroundImageIsPlayiingbackgroundImageIsPlayiing)
        {
            HideBackgroundVideoHideVideo(displayref x);
        }
        if (displayx.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            displayx.FrontDisplayElement1.Visibility =
            displayx.FrontDisplayElement2.Visibility =
                displayx.FrontDisplayElement3.Visibility = displayx.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        displayx.FrontDisplayElement1.Source = displayx.FrontDisplayElement2.Source = displayx.FrontDisplayElement3.Source = displayx.FrontDisplayElement4.Source = new Uri(urla);
        displayx.FrontDisplayElement1.Play();
        displayx.FrontDisplayElement2.Play();
        displayx.FrontDisplayElement3.Play();
        displayx.FrontDisplayElement4.Play();
        _videoIsPlayingvideoIsPlaying = true;
        displayx.FrontDisplayElement1.MediaEnded += video_MediaEnded;new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start Music
    /// </summary>
    /// <param name="b"></param>
    /// <param name="url"></param>
    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += sound_MediaEnded;new EventHandler(sound_MediaEnded);
        _musicIsPlayingmusicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Displays Text
    /// </summary>
    /// <param name="display"></param>
    private void DisplayText(ref Display displayt)
    {
        HideVideoHolo(displayref t);
        HideImages(displayref t);
        displayt.textBlock1.Text = displayt.textBlock2.Text = displayt.textBlock3.Text = displayt.textBlock4.Text = textBox.Text;
        _textIsDisplayingtextIsDisplaying = true;
    }
    
    /// <summary>
    /// Displays Images
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void DisplayImage(ref Display displayy, string urlx)
    {
        if (_videoIsPlayingvideoIsPlaying)
        {
            HideVideoHolo(displayref y);
            
        }
        if (displayy.image.Visibility == Visibility.Hidden)
        {
            displayy.image.Visibility = displayy.image1.Visibility = displayy.image2.Visibility = displayy.image3.Visibility = Visibility.Visible;
            _imageIsDisplayingimageIsDisplaying = false;
        }
        displayy.image.Source = displayy.image1.Source = displayy.image2.Source = displayy.image3.Source = new BitmapImage(new Uri(urlx));
        _imageIsDisplayingimageIsDisplaying = true;
    }

    /// <summary>
    /// Removes Text
    /// </summary>
    /// <param name="display"></param>
    private void HideText(ref Display displayt)
    {
        displayt.textBlock1.Text = displayt.textBlock2.Text = displayt.textBlock3.Text = displayt.textBlock4.Text = null;
        _textIsDisplayingtextIsDisplaying = false;
    }

    /// <summary>
    /// Remove pictures
    /// </summary>
    /// <param name="display"></param>
    private void HideImages(ref Display displayf)
    {
        displayf.image.Visibility = displayf.image1.Visibility = displayf.image2.Visibility = displayf.image3.Visibility = Visibility.Hidden;
        _imageIsDisplayingimageIsDisplaying = false;
    }

    /// <summary>
    /// Removes front videos
    /// </summary>
    /// <param name="display"></param>
    private void HideVideoHolo(ref Display displayf)
    {
        displayf.FrontDisplayElement1.Visibility =
            displayf.FrontDisplayElement2.Visibility =
                displayf.FrontDisplayElement3.Visibility = displayf.FrontDisplayElement4.Visibility = Visibility.Hidden;
        displayf.FrontDisplayElement1.Close();
        displayf.FrontDisplayElement2.Close();
        displayf.FrontDisplayElement3.Close();
        displayf.FrontDisplayElement4.Close();
        _videoIsPlayingvideoIsPlaying = false;
    }

    /// <summary>
    /// Removes background video
    /// </summary>
    /// <param name="display"></param>
    private void HideBackgroundVideoHideVideo(ref Display displayf)
    {
        displayf.BackgroundMediaElement.Close();
        _backgroundImageIsPlayiingbackgroundImageIsPlayiing = false;
    }

    /// <summary>
    /// Loop background video if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void BackgroundMediaElement_MediaEndedme_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    /// <summary>
    /// Loop front videos if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void video_MediaEndedvid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    /// <summary>
    /// Loop music if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _raoulraoul.Position = TimeSpan.FromMilliseconds(1);
        _raoulraoul.Play();
        _musicIsPlayingmusicIsPlaying = true;
    }
    #endregion
    
    /// <summary>
    /// Use echap key to exit program
    /// </summary>
    /// <param name="sender"></param>
    /// <param#region name="e"></param>Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}

}

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    /// <summary>
    /// New WPF Window
    /// </summary>
    private Display _avc = new Display();
    /// <summary>
    /// Mp3 Player
    /// </summary>
    private MediaPlayer _raoul = new MediaPlayer();
    
    private bool _videoIsPlaying;
    private bool _imageIsDisplaying;
    private bool _backgroundImageIsPlayiing;
    private bool _textIsDisplaying;
    private bool _musicIsPlaying;
    
    /// <summary>
    /// Video Url
    /// </summary>
    private readonly string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    /// <summary>
    /// Video Url Accessors
    /// </summary>
    public string VideoUrl => _videoUrl;
    
    /// <summary>
    /// Constructor
    /// </summary>
    public MainWindow()
    {
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        PreviewKeyDown += HandleEsc;
    }

    /// <summary>
    /// Closes Program if Window closed
    /// </summary>
    /// <param name="e"></param>
    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }

    
    /// <summary>
    /// Button putting Text into next Window
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(_avc);
    }

    /// <summary>
    /// Media Opener
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            var fileExtention = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (fileExtention)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    _raoul.Close();
                    _raoul.Open(new Uri(openFileDialog.FileName));
                    _raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(_avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(_avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    /// <summary>
    /// Restart Media / Play Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!_musicIsPlaying)
        {
            _raoul.Play();
            _musicIsPlaying = true;
        }
        if (_backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (_videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Pause Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (_musicIsPlaying)
        {
            _raoul.Pause();
            _musicIsPlaying = false;
        }
        if (_backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (_videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        _backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        _backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        _backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        _backgroundImageIsPlayiing = true;
    }

    
    /// <summary>
    /// Tetris Theme
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"tetris.mp3");
    }

    /// <summary>
    /// We are Number One - Lazy Town
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"wano.mp3");
    }

    /// <summary>
    /// Ultimate - Denzel Curry
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"ultimate.mp3");
    }

    /// <summary>
    /// CsGo theme Song
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"csgo.mp3");
    }
    
    /// <summary>
    /// Sets Medialement Url
    /// </summary>
    /// <param name="a"></param>
    /// <param name="url"></param>
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += BackgroundMediaElement_MediaEnded;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start front Videos
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void PlayVideoHolo(Display display, string url)
    {

        if (_imageIsDisplaying)
        {
            HideImages(display);
        }
        if (_textIsDisplaying)
        {
            HideText(display);
        }
        if (_backgroundImageIsPlayiing)
        {
            HideBackgroundVideo(display);
        }
        if (display.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            display.FrontDisplayElement1.Visibility =
            display.FrontDisplayElement2.Visibility =
                display.FrontDisplayElement3.Visibility = display.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        display.FrontDisplayElement1.Source = display.FrontDisplayElement2.Source = display.FrontDisplayElement3.Source = display.FrontDisplayElement4.Source = new Uri(url);
        display.FrontDisplayElement1.Play();
        display.FrontDisplayElement2.Play();
        display.FrontDisplayElement3.Play();
        display.FrontDisplayElement4.Play();
        _videoIsPlaying = true;
        display.FrontDisplayElement1.MediaEnded += video_MediaEnded;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start Music
    /// </summary>
    /// <param name="b"></param>
    /// <param name="url"></param>
    private void PlaySound(MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += sound_MediaEnded;
        _musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Displays Text
    /// </summary>
    /// <param name="display"></param>
    private void DisplayText(Display display)
    {
        HideVideoHolo(display);
        HideImages(display);
        display.textBlock1.Text = display.textBlock2.Text = display.textBlock3.Text = display.textBlock4.Text = textBox.Text;
        _textIsDisplaying = true;
    }
    
    /// <summary>
    /// Displays Images
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void DisplayImage(Display display, string url)
    {
        if (_videoIsPlaying)
        {
            HideVideoHolo(display);
            
        }
        if (display.image.Visibility == Visibility.Hidden)
        {
            display.image.Visibility = display.image1.Visibility = display.image2.Visibility = display.image3.Visibility = Visibility.Visible;
            _imageIsDisplaying = false;
        }
        display.image.Source = display.image1.Source = display.image2.Source = display.image3.Source = new BitmapImage(new Uri(url));
        _imageIsDisplaying = true;
    }

    /// <summary>
    /// Removes Text
    /// </summary>
    /// <param name="display"></param>
    private void HideText(Display display)
    {
        display.textBlock1.Text = display.textBlock2.Text = display.textBlock3.Text = display.textBlock4.Text = null;
        _textIsDisplaying = false;
    }

    /// <summary>
    /// Remove pictures
    /// </summary>
    /// <param name="display"></param>
    private void HideImages(Display display)
    {
        display.image.Visibility = display.image1.Visibility = display.image2.Visibility = display.image3.Visibility = Visibility.Hidden;
        _imageIsDisplaying = false;
    }

    /// <summary>
    /// Removes front videos
    /// </summary>
    /// <param name="display"></param>
    private void HideVideoHolo(Display display)
    {
        display.FrontDisplayElement1.Visibility =
            display.FrontDisplayElement2.Visibility =
                display.FrontDisplayElement3.Visibility = display.FrontDisplayElement4.Visibility = Visibility.Hidden;
        display.FrontDisplayElement1.Close();
        display.FrontDisplayElement2.Close();
        display.FrontDisplayElement3.Close();
        display.FrontDisplayElement4.Close();
        _videoIsPlaying = false;
    }

    /// <summary>
    /// Removes background video
    /// </summary>
    /// <param name="display"></param>
    private void HideBackgroundVideo(Display display)
    {
        display.BackgroundMediaElement.Close();
        _backgroundImageIsPlayiing = false;
    }

    /// <summary>
    /// Loop background video if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void BackgroundMediaElement_MediaEnded(object sender, EventArgs e)
    {
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    /// <summary>
    /// Loop front videos if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void video_MediaEnded(object sender, EventArgs e)
    {
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    /// <summary>
    /// Loop music if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _raoul.Position = TimeSpan.FromMilliseconds(1);
        _raoul.Play();
        _musicIsPlaying = true;
    }
    
    /// <summary>
    /// Use echap key to exit program
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }
}

}

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
public partial class MainWindow : Window
{
    #region Medias
    private Display _avc = new Display();
    MediaPlayer raoul = new MediaPlayer();
    #endregion

    #region Booleans
    private bool videoIsPlaying = false;
    private bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;

    #endregion

    #region Constructor & override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            string str = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (str)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul.Close();
                    raoul.Open(new Uri(openFileDialog.FileName));
                    raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying)
        {
            raoul.Play();
            musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying)
        {
            raoul.Pause();
            musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    
    #region ListBox of videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing = true;
    }
    #endregion

    #region ListBox of music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"tetris.mp3");
    }

    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"wano.mp3");
    }

    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"ultimate.mp3");
    }

    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"csgo.mp3");
    }
    #endregion


    #region Videos, Text and Sound Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlayVideoHolo(ref Display x, string a)
    {

        if (imageIsDisplaying)
        {
            HideImages(ref x);
        }
        if (textIsDisplaying)
        {
            HideText(ref x);
        }
        if (backgroundImageIsPlayiing)
        {
            HideVideo(ref x);
        }
        if (x.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            x.FrontDisplayElement1.Visibility =
            x.FrontDisplayElement2.Visibility =
                x.FrontDisplayElement3.Visibility = x.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        x.FrontDisplayElement1.Source = x.FrontDisplayElement2.Source = x.FrontDisplayElement3.Source = x.FrontDisplayElement4.Source = new Uri(a);
        x.FrontDisplayElement1.Play();
        x.FrontDisplayElement2.Play();
        x.FrontDisplayElement3.Play();
        x.FrontDisplayElement4.Play();
        videoIsPlaying = true;
        x.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);
        musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    private void DisplayText(ref Display t)
    {
        HideVideoHolo(ref t);
        HideImages(ref t);
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = textBox.Text;
        textIsDisplaying = true;
    }
    
    private void DisplayImage(ref Display y, string x)
    {
        if (videoIsPlaying)
        {
            HideVideoHolo(ref y);
            
        }
        if (y.image.Visibility == Visibility.Hidden)
        {
            y.image.Visibility = y.image1.Visibility = y.image2.Visibility = y.image3.Visibility = Visibility.Visible;
            imageIsDisplaying = false;
        }
        y.image.Source = y.image1.Source = y.image2.Source = y.image3.Source = new BitmapImage(new Uri(x));
        imageIsDisplaying = true;
    }

    private void HideText(ref Display t)
    {
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = null;
        textIsDisplaying = false;
    }

    private void HideImages(ref Display f)
    {
        f.image.Visibility = f.image1.Visibility = f.image2.Visibility = f.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying = false;
    }

    private void HideVideoHolo(ref Display f)
    {
        f.FrontDisplayElement1.Visibility =
            f.FrontDisplayElement2.Visibility =
                f.FrontDisplayElement3.Visibility = f.FrontDisplayElement4.Visibility = Visibility.Hidden;
        f.FrontDisplayElement1.Close();
        f.FrontDisplayElement2.Close();
        f.FrontDisplayElement3.Close();
        f.FrontDisplayElement4.Close();
        videoIsPlaying = false;
    }

    private void HideVideo(ref Display f)
    {
        f.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing = false;
    }

    void me_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    void vid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul.Play();
        musicIsPlaying = true;
    }
    #endregion
    
    #region Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}
Summarys, removed "#region", renamed var
Source Link
Cédric
  • 173
  • 7
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    #region/// Medias<summary>
    /// New WPF Window
    /// </summary>
    private Display _avc = new Display();
    /// <summary>
    /// Mp3 Player
    /// </summary>
    private MediaPlayer raoul_raoul = new MediaPlayer();
    #endregion

    #regionprivate Booleansbool _videoIsPlaying;
    private bool videoIsPlaying = false;_imageIsDisplaying;
    private bool imageIsDisplaying = false;_backgroundImageIsPlayiing;
    private bool backgroundImageIsPlayiing = false;_textIsDisplaying;
    private bool textIsDisplaying = false;_musicIsPlaying;
    private 
 bool musicIsPlaying = false;/// <summary>
    #endregion
/// Video Url
    #region/// Url</summary>
    private readonly string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    /// <summary>
    /// Video Url Accessors
    /// </summary>
    public string VideoUrl => _videoUrl;

     #endregion
    /// <summary>
    #region/// Constructor 
 & override  /// </summary>
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/HandleEsc;
    }

    /// <summary>
    /// Closes Program if Window closed
    /// </summary>
    /// <param name="e"></param>
    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region 
 Buttons   /// <summary>
    /// Button putting Text into next Window
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    /// <summary>
    /// Media Opener
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            stringvar strfileExtention = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (strfileExtention)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul_raoul.Close();
                    raoul_raoul.Open(new Uri(openFileDialog.FileName));
                    raoul_raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    /// <summary>
    /// Restart Media / Play Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying_musicIsPlaying)
        {
            raoul_raoul.Play();
            musicIsPlaying_musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing_backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying_videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Pause Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying_musicIsPlaying)
        {
            raoul_raoul.Pause();
            musicIsPlaying_musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing_backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying_videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    /// <summary>
    #region/// ListBoxDisplays ofPreconfigured videosBackground Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying_imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying_textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying_videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing_backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying_imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying_textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying_videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing_backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying_imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying_textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying_videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing_backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying_imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying_textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying_videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing_backgroundImageIsPlayiing = true;
    }
    #endregion

    #region 
 ListBox of music /// <summary>
    /// Tetris Theme
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul_raoul, @"tetris.mp3");
    }

    /// <summary>
    /// We are Number One - Lazy Town
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul_raoul, @"wano.mp3");
    }

    /// <summary>
    /// Ultimate - Denzel Curry
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul_raoul, @"ultimate.mp3");
    }

    /// <summary>
    /// CsGo theme Song
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul_raoul, @"csgo.mp3");
    }
    #endregion
    /// <summary>
    /// Sets Medialement Url
    #region/// Videos,</summary>
 Text and Sound Player/// <param name="a"></param>
    /// <param name="url"></param>
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);BackgroundMediaElement_MediaEnded;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start front Videos
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void PlayVideoHolo(ref Display xdisplay, string aurl)
    {

        if (imageIsDisplaying_imageIsDisplaying)
        {
            HideImages(ref xdisplay);
        }
        if (textIsDisplaying_textIsDisplaying)
        {
            HideText(ref xdisplay);
        }
        if (backgroundImageIsPlayiing_backgroundImageIsPlayiing)
        {
            HideVideoHideBackgroundVideo(ref xdisplay);
        }
        if (xdisplay.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            xdisplay.FrontDisplayElement1.Visibility =
            xdisplay.FrontDisplayElement2.Visibility =
                xdisplay.FrontDisplayElement3.Visibility = xdisplay.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        xdisplay.FrontDisplayElement1.Source = xdisplay.FrontDisplayElement2.Source = xdisplay.FrontDisplayElement3.Source = xdisplay.FrontDisplayElement4.Source = new Uri(aurl);
        xdisplay.FrontDisplayElement1.Play();
        xdisplay.FrontDisplayElement2.Play();
        xdisplay.FrontDisplayElement3.Play();
        xdisplay.FrontDisplayElement4.Play();
        videoIsPlaying_videoIsPlaying = true;
        xdisplay.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);video_MediaEnded;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start Music
    /// </summary>
    /// <param name="b"></param>
    /// <param name="url"></param>
    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);sound_MediaEnded;
        musicIsPlaying_musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Displays Text
    /// </summary>
    /// <param name="display"></param>
    private void DisplayText(ref Display tdisplay)
    {
        HideVideoHolo(ref tdisplay);
        HideImages(ref tdisplay);
        tdisplay.textBlock1.Text = tdisplay.textBlock2.Text = tdisplay.textBlock3.Text = tdisplay.textBlock4.Text = textBox.Text;
        textIsDisplaying_textIsDisplaying = true;
    }
    
    /// <summary>
    /// Displays Images
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void DisplayImage(ref Display ydisplay, string xurl)
    {
        if (videoIsPlaying_videoIsPlaying)
        {
            HideVideoHolo(ref ydisplay);
            
        }
        if (ydisplay.image.Visibility == Visibility.Hidden)
        {
            ydisplay.image.Visibility = ydisplay.image1.Visibility = ydisplay.image2.Visibility = ydisplay.image3.Visibility = Visibility.Visible;
            imageIsDisplaying_imageIsDisplaying = false;
        }
        ydisplay.image.Source = ydisplay.image1.Source = ydisplay.image2.Source = ydisplay.image3.Source = new BitmapImage(new Uri(xurl));
        imageIsDisplaying_imageIsDisplaying = true;
    }

    /// <summary>
    /// Removes Text
    /// </summary>
    /// <param name="display"></param>
    private void HideText(ref Display tdisplay)
    {
        tdisplay.textBlock1.Text = tdisplay.textBlock2.Text = tdisplay.textBlock3.Text = tdisplay.textBlock4.Text = null;
        textIsDisplaying_textIsDisplaying = false;
    }

    /// <summary>
    /// Remove pictures
    /// </summary>
    /// <param name="display"></param>
    private void HideImages(ref Display fdisplay)
    {
        fdisplay.image.Visibility = fdisplay.image1.Visibility = fdisplay.image2.Visibility = fdisplay.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying_imageIsDisplaying = false;
    }

    /// <summary>
    /// Removes front videos
    /// </summary>
    /// <param name="display"></param>
    private void HideVideoHolo(ref Display fdisplay)
    {
        fdisplay.FrontDisplayElement1.Visibility =
            fdisplay.FrontDisplayElement2.Visibility =
                fdisplay.FrontDisplayElement3.Visibility = fdisplay.FrontDisplayElement4.Visibility = Visibility.Hidden;
        fdisplay.FrontDisplayElement1.Close();
        fdisplay.FrontDisplayElement2.Close();
        fdisplay.FrontDisplayElement3.Close();
        fdisplay.FrontDisplayElement4.Close();
        videoIsPlaying_videoIsPlaying = false;
    }

    /// <summary>
    /// Removes background video
    /// </summary>
    /// <param name="display"></param>
    private void HideVideoHideBackgroundVideo(ref Display fdisplay)
    {
        fdisplay.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing_backgroundImageIsPlayiing = false;
    }

    /// <summary>
    /// Loop background video if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void me_MediaEndedBackgroundMediaElement_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    /// <summary>
    /// Loop front videos if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void vid_MediaEndedvideo_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    /// <summary>
    /// Loop music if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul_raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul_raoul.Play();
        musicIsPlaying_musicIsPlaying = true;
    }
    #endregion
    
    #region/// Keyhandler<summary>
    /// Use echap key to exit program
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}

}

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
public partial class MainWindow : Window
{
    #region Medias
    private Display _avc = new Display();
    MediaPlayer raoul = new MediaPlayer();
    #endregion

    #region Booleans
    private bool videoIsPlaying = false;
    private bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;

     #endregion

    #region Constructor & override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            string str = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (str)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul.Close();
                    raoul.Open(new Uri(openFileDialog.FileName));
                    raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying)
        {
            raoul.Play();
            musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying)
        {
            raoul.Pause();
            musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    
    #region ListBox of videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing = true;
    }
    #endregion

    #region ListBox of music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"tetris.mp3");
    }

    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"wano.mp3");
    }

    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"ultimate.mp3");
    }

    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"csgo.mp3");
    }
    #endregion


    #region Videos, Text and Sound Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlayVideoHolo(ref Display x, string a)
    {

        if (imageIsDisplaying)
        {
            HideImages(ref x);
        }
        if (textIsDisplaying)
        {
            HideText(ref x);
        }
        if (backgroundImageIsPlayiing)
        {
            HideVideo(ref x);
        }
        if (x.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            x.FrontDisplayElement1.Visibility =
            x.FrontDisplayElement2.Visibility =
                x.FrontDisplayElement3.Visibility = x.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        x.FrontDisplayElement1.Source = x.FrontDisplayElement2.Source = x.FrontDisplayElement3.Source = x.FrontDisplayElement4.Source = new Uri(a);
        x.FrontDisplayElement1.Play();
        x.FrontDisplayElement2.Play();
        x.FrontDisplayElement3.Play();
        x.FrontDisplayElement4.Play();
        videoIsPlaying = true;
        x.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);
        musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    private void DisplayText(ref Display t)
    {
        HideVideoHolo(ref t);
        HideImages(ref t);
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = textBox.Text;
        textIsDisplaying = true;
    }
    
    private void DisplayImage(ref Display y, string x)
    {
        if (videoIsPlaying)
        {
            HideVideoHolo(ref y);
            
        }
        if (y.image.Visibility == Visibility.Hidden)
        {
            y.image.Visibility = y.image1.Visibility = y.image2.Visibility = y.image3.Visibility = Visibility.Visible;
            imageIsDisplaying = false;
        }
        y.image.Source = y.image1.Source = y.image2.Source = y.image3.Source = new BitmapImage(new Uri(x));
        imageIsDisplaying = true;
    }

    private void HideText(ref Display t)
    {
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = null;
        textIsDisplaying = false;
    }

    private void HideImages(ref Display f)
    {
        f.image.Visibility = f.image1.Visibility = f.image2.Visibility = f.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying = false;
    }

    private void HideVideoHolo(ref Display f)
    {
        f.FrontDisplayElement1.Visibility =
            f.FrontDisplayElement2.Visibility =
                f.FrontDisplayElement3.Visibility = f.FrontDisplayElement4.Visibility = Visibility.Hidden;
        f.FrontDisplayElement1.Close();
        f.FrontDisplayElement2.Close();
        f.FrontDisplayElement3.Close();
        f.FrontDisplayElement4.Close();
        videoIsPlaying = false;
    }

    private void HideVideo(ref Display f)
    {
        f.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing = false;
    }

    void me_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    void vid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul.Play();
        musicIsPlaying = true;
    }
    #endregion
    
    #region Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    /// <summary>
    /// New WPF Window
    /// </summary>
    private Display _avc = new Display();
    /// <summary>
    /// Mp3 Player
    /// </summary>
    private MediaPlayer _raoul = new MediaPlayer();
    
    private bool _videoIsPlaying;
    private bool _imageIsDisplaying;
    private bool _backgroundImageIsPlayiing;
    private bool _textIsDisplaying;
    private bool _musicIsPlaying;
     
    /// <summary>
    /// Video Url
    /// </summary>
    private readonly string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    /// <summary>
    /// Video Url Accessors
    /// </summary>
    public string VideoUrl => _videoUrl;
    
    /// <summary>
    /// Constructor 
    /// </summary>
    public MainWindow()
    {
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        PreviewKeyDown += HandleEsc;
    }

    /// <summary>
    /// Closes Program if Window closed
    /// </summary>
    /// <param name="e"></param>
    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }

     
    /// <summary>
    /// Button putting Text into next Window
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(_avc);
    }

    /// <summary>
    /// Media Opener
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            var fileExtention = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (fileExtention)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    _raoul.Close();
                    _raoul.Open(new Uri(openFileDialog.FileName));
                    _raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(_avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(_avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    /// <summary>
    /// Restart Media / Play Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!_musicIsPlaying)
        {
            _raoul.Play();
            _musicIsPlaying = true;
        }
        if (_backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (_videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Pause Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (_musicIsPlaying)
        {
            _raoul.Pause();
            _musicIsPlaying = false;
        }
        if (_backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (_videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        _backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        _backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        _backgroundImageIsPlayiing = true;
    }

    /// <summary>
    /// Displays Preconfigured Background Video
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (_imageIsDisplaying)
        {
            HideImages(_avc);
        }
        if (_textIsDisplaying)
        {
            HideText(_avc);
        }
        if (_videoIsPlaying)
        {
            HideVideoHolo(_avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        _backgroundImageIsPlayiing = true;
    }

     
    /// <summary>
    /// Tetris Theme
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"tetris.mp3");
    }

    /// <summary>
    /// We are Number One - Lazy Town
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"wano.mp3");
    }

    /// <summary>
    /// Ultimate - Denzel Curry
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"ultimate.mp3");
    }

    /// <summary>
    /// CsGo theme Song
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(_raoul, @"csgo.mp3");
    }
    
    /// <summary>
    /// Sets Medialement Url
    /// </summary>
    /// <param name="a"></param>
    /// <param name="url"></param>
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += BackgroundMediaElement_MediaEnded;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start front Videos
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void PlayVideoHolo(Display display, string url)
    {

        if (_imageIsDisplaying)
        {
            HideImages(display);
        }
        if (_textIsDisplaying)
        {
            HideText(display);
        }
        if (_backgroundImageIsPlayiing)
        {
            HideBackgroundVideo(display);
        }
        if (display.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            display.FrontDisplayElement1.Visibility =
            display.FrontDisplayElement2.Visibility =
                display.FrontDisplayElement3.Visibility = display.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        display.FrontDisplayElement1.Source = display.FrontDisplayElement2.Source = display.FrontDisplayElement3.Source = display.FrontDisplayElement4.Source = new Uri(url);
        display.FrontDisplayElement1.Play();
        display.FrontDisplayElement2.Play();
        display.FrontDisplayElement3.Play();
        display.FrontDisplayElement4.Play();
        _videoIsPlaying = true;
        display.FrontDisplayElement1.MediaEnded += video_MediaEnded;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Load & Start Music
    /// </summary>
    /// <param name="b"></param>
    /// <param name="url"></param>
    private void PlaySound(MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += sound_MediaEnded;
        _musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    /// <summary>
    /// Displays Text
    /// </summary>
    /// <param name="display"></param>
    private void DisplayText(Display display)
    {
        HideVideoHolo(display);
        HideImages(display);
        display.textBlock1.Text = display.textBlock2.Text = display.textBlock3.Text = display.textBlock4.Text = textBox.Text;
        _textIsDisplaying = true;
    }
    
    /// <summary>
    /// Displays Images
    /// </summary>
    /// <param name="display"></param>
    /// <param name="url"></param>
    private void DisplayImage(Display display, string url)
    {
        if (_videoIsPlaying)
        {
            HideVideoHolo(display);
            
        }
        if (display.image.Visibility == Visibility.Hidden)
        {
            display.image.Visibility = display.image1.Visibility = display.image2.Visibility = display.image3.Visibility = Visibility.Visible;
            _imageIsDisplaying = false;
        }
        display.image.Source = display.image1.Source = display.image2.Source = display.image3.Source = new BitmapImage(new Uri(url));
        _imageIsDisplaying = true;
    }

    /// <summary>
    /// Removes Text
    /// </summary>
    /// <param name="display"></param>
    private void HideText(Display display)
    {
        display.textBlock1.Text = display.textBlock2.Text = display.textBlock3.Text = display.textBlock4.Text = null;
        _textIsDisplaying = false;
    }

    /// <summary>
    /// Remove pictures
    /// </summary>
    /// <param name="display"></param>
    private void HideImages(Display display)
    {
        display.image.Visibility = display.image1.Visibility = display.image2.Visibility = display.image3.Visibility = Visibility.Hidden;
        _imageIsDisplaying = false;
    }

    /// <summary>
    /// Removes front videos
    /// </summary>
    /// <param name="display"></param>
    private void HideVideoHolo(Display display)
    {
        display.FrontDisplayElement1.Visibility =
            display.FrontDisplayElement2.Visibility =
                display.FrontDisplayElement3.Visibility = display.FrontDisplayElement4.Visibility = Visibility.Hidden;
        display.FrontDisplayElement1.Close();
        display.FrontDisplayElement2.Close();
        display.FrontDisplayElement3.Close();
        display.FrontDisplayElement4.Close();
        _videoIsPlaying = false;
    }

    /// <summary>
    /// Removes background video
    /// </summary>
    /// <param name="display"></param>
    private void HideBackgroundVideo(Display display)
    {
        display.BackgroundMediaElement.Close();
        _backgroundImageIsPlayiing = false;
    }

    /// <summary>
    /// Loop background video if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void BackgroundMediaElement_MediaEnded(object sender, EventArgs e)
    {
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    /// <summary>
    /// Loop front videos if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void video_MediaEnded(object sender, EventArgs e)
    {
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    /// <summary>
    /// Loop music if ended
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _raoul.Position = TimeSpan.FromMilliseconds(1);
        _raoul.Play();
        _musicIsPlaying = true;
    }
    
    /// <summary>
    /// Use echap key to exit program
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }
}

}

added language formatting
Source Link
t3chb0t
  • 44.7k
  • 9
  • 84
  • 191
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
public partial class MainWindow : Window
{
    #region Medias
    private Display _avc = new Display();
    MediaPlayer raoul = new MediaPlayer();
    #endregion

    #region Booleans
    private bool videoIsPlaying = false;
    private bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;

    #endregion

    #region Constructor & override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            string str = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (str)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul.Close();
                    raoul.Open(new Uri(openFileDialog.FileName));
                    raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying)
        {
            raoul.Play();
            musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying)
        {
            raoul.Pause();
            musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    
    #region ListBox of videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing = true;
    }
    #endregion

    #region ListBox of music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"tetris.mp3");
    }

    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"wano.mp3");
    }

    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"ultimate.mp3");
    }

    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"csgo.mp3");
    }
    #endregion


    #region Videos, Text and Sound Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlayVideoHolo(ref Display x, string a)
    {

        if (imageIsDisplaying)
        {
            HideImages(ref x);
        }
        if (textIsDisplaying)
        {
            HideText(ref x);
        }
        if (backgroundImageIsPlayiing)
        {
            HideVideo(ref x);
        }
        if (x.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            x.FrontDisplayElement1.Visibility =
            x.FrontDisplayElement2.Visibility =
                x.FrontDisplayElement3.Visibility = x.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        x.FrontDisplayElement1.Source = x.FrontDisplayElement2.Source = x.FrontDisplayElement3.Source = x.FrontDisplayElement4.Source = new Uri(a);
        x.FrontDisplayElement1.Play();
        x.FrontDisplayElement2.Play();
        x.FrontDisplayElement3.Play();
        x.FrontDisplayElement4.Play();
        videoIsPlaying = true;
        x.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);
        musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    private void DisplayText(ref Display t)
    {
        HideVideoHolo(ref t);
        HideImages(ref t);
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = textBox.Text;
        textIsDisplaying = true;
    }
    
    private void DisplayImage(ref Display y, string x)
    {
        if (videoIsPlaying)
        {
            HideVideoHolo(ref y);
            
        }
        if (y.image.Visibility == Visibility.Hidden)
        {
            y.image.Visibility = y.image1.Visibility = y.image2.Visibility = y.image3.Visibility = Visibility.Visible;
            imageIsDisplaying = false;
        }
        y.image.Source = y.image1.Source = y.image2.Source = y.image3.Source = new BitmapImage(new Uri(x));
        imageIsDisplaying = true;
    }

    private void HideText(ref Display t)
    {
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = null;
        textIsDisplaying = false;
    }

    private void HideImages(ref Display f)
    {
        f.image.Visibility = f.image1.Visibility = f.image2.Visibility = f.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying = false;
    }

    private void HideVideoHolo(ref Display f)
    {
        f.FrontDisplayElement1.Visibility =
            f.FrontDisplayElement2.Visibility =
                f.FrontDisplayElement3.Visibility = f.FrontDisplayElement4.Visibility = Visibility.Hidden;
        f.FrontDisplayElement1.Close();
        f.FrontDisplayElement2.Close();
        f.FrontDisplayElement3.Close();
        f.FrontDisplayElement4.Close();
        videoIsPlaying = false;
    }

    private void HideVideo(ref Display f)
    {
        f.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing = false;
    }

    void me_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    void vid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul.Play();
        musicIsPlaying = true;
    }
    #endregion
    
    #region Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
public partial class MainWindow : Window
{
    #region Medias
    private Display _avc = new Display();
    MediaPlayer raoul = new MediaPlayer();
    #endregion

    #region Booleans
    private bool videoIsPlaying = false;
    private bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;

    #endregion

    #region Constructor & override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            string str = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (str)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul.Close();
                    raoul.Open(new Uri(openFileDialog.FileName));
                    raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying)
        {
            raoul.Play();
            musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying)
        {
            raoul.Pause();
            musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    
    #region ListBox of videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing = true;
    }
    #endregion

    #region ListBox of music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"tetris.mp3");
    }

    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"wano.mp3");
    }

    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"ultimate.mp3");
    }

    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"csgo.mp3");
    }
    #endregion


    #region Videos, Text and Sound Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlayVideoHolo(ref Display x, string a)
    {

        if (imageIsDisplaying)
        {
            HideImages(ref x);
        }
        if (textIsDisplaying)
        {
            HideText(ref x);
        }
        if (backgroundImageIsPlayiing)
        {
            HideVideo(ref x);
        }
        if (x.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            x.FrontDisplayElement1.Visibility =
            x.FrontDisplayElement2.Visibility =
                x.FrontDisplayElement3.Visibility = x.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        x.FrontDisplayElement1.Source = x.FrontDisplayElement2.Source = x.FrontDisplayElement3.Source = x.FrontDisplayElement4.Source = new Uri(a);
        x.FrontDisplayElement1.Play();
        x.FrontDisplayElement2.Play();
        x.FrontDisplayElement3.Play();
        x.FrontDisplayElement4.Play();
        videoIsPlaying = true;
        x.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);
        musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    private void DisplayText(ref Display t)
    {
        HideVideoHolo(ref t);
        HideImages(ref t);
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = textBox.Text;
        textIsDisplaying = true;
    }
    
    private void DisplayImage(ref Display y, string x)
    {
        if (videoIsPlaying)
        {
            HideVideoHolo(ref y);
            
        }
        if (y.image.Visibility == Visibility.Hidden)
        {
            y.image.Visibility = y.image1.Visibility = y.image2.Visibility = y.image3.Visibility = Visibility.Visible;
            imageIsDisplaying = false;
        }
        y.image.Source = y.image1.Source = y.image2.Source = y.image3.Source = new BitmapImage(new Uri(x));
        imageIsDisplaying = true;
    }

    private void HideText(ref Display t)
    {
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = null;
        textIsDisplaying = false;
    }

    private void HideImages(ref Display f)
    {
        f.image.Visibility = f.image1.Visibility = f.image2.Visibility = f.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying = false;
    }

    private void HideVideoHolo(ref Display f)
    {
        f.FrontDisplayElement1.Visibility =
            f.FrontDisplayElement2.Visibility =
                f.FrontDisplayElement3.Visibility = f.FrontDisplayElement4.Visibility = Visibility.Hidden;
        f.FrontDisplayElement1.Close();
        f.FrontDisplayElement2.Close();
        f.FrontDisplayElement3.Close();
        f.FrontDisplayElement4.Close();
        videoIsPlaying = false;
    }

    private void HideVideo(ref Display f)
    {
        f.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing = false;
    }

    void me_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    void vid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul.Play();
        musicIsPlaying = true;
    }
    #endregion
    
    #region Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
public partial class MainWindow : Window
{
    #region Medias
    private Display _avc = new Display();
    MediaPlayer raoul = new MediaPlayer();
    #endregion

    #region Booleans
    private bool videoIsPlaying = false;
    private bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;

    #endregion

    #region Constructor & override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            string str = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (str)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul.Close();
                    raoul.Open(new Uri(openFileDialog.FileName));
                    raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying)
        {
            raoul.Play();
            musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying)
        {
            raoul.Pause();
            musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    
    #region ListBox of videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing = true;
    }
    #endregion

    #region ListBox of music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"tetris.mp3");
    }

    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"wano.mp3");
    }

    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"ultimate.mp3");
    }

    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"csgo.mp3");
    }
    #endregion


    #region Videos, Text and Sound Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlayVideoHolo(ref Display x, string a)
    {

        if (imageIsDisplaying)
        {
            HideImages(ref x);
        }
        if (textIsDisplaying)
        {
            HideText(ref x);
        }
        if (backgroundImageIsPlayiing)
        {
            HideVideo(ref x);
        }
        if (x.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            x.FrontDisplayElement1.Visibility =
            x.FrontDisplayElement2.Visibility =
                x.FrontDisplayElement3.Visibility = x.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        x.FrontDisplayElement1.Source = x.FrontDisplayElement2.Source = x.FrontDisplayElement3.Source = x.FrontDisplayElement4.Source = new Uri(a);
        x.FrontDisplayElement1.Play();
        x.FrontDisplayElement2.Play();
        x.FrontDisplayElement3.Play();
        x.FrontDisplayElement4.Play();
        videoIsPlaying = true;
        x.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);
        musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    private void DisplayText(ref Display t)
    {
        HideVideoHolo(ref t);
        HideImages(ref t);
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = textBox.Text;
        textIsDisplaying = true;
    }
    
    private void DisplayImage(ref Display y, string x)
    {
        if (videoIsPlaying)
        {
            HideVideoHolo(ref y);
            
        }
        if (y.image.Visibility == Visibility.Hidden)
        {
            y.image.Visibility = y.image1.Visibility = y.image2.Visibility = y.image3.Visibility = Visibility.Visible;
            imageIsDisplaying = false;
        }
        y.image.Source = y.image1.Source = y.image2.Source = y.image3.Source = new BitmapImage(new Uri(x));
        imageIsDisplaying = true;
    }

    private void HideText(ref Display t)
    {
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = null;
        textIsDisplaying = false;
    }

    private void HideImages(ref Display f)
    {
        f.image.Visibility = f.image1.Visibility = f.image2.Visibility = f.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying = false;
    }

    private void HideVideoHolo(ref Display f)
    {
        f.FrontDisplayElement1.Visibility =
            f.FrontDisplayElement2.Visibility =
                f.FrontDisplayElement3.Visibility = f.FrontDisplayElement4.Visibility = Visibility.Hidden;
        f.FrontDisplayElement1.Close();
        f.FrontDisplayElement2.Close();
        f.FrontDisplayElement3.Close();
        f.FrontDisplayElement4.Close();
        videoIsPlaying = false;
    }

    private void HideVideo(ref Display f)
    {
        f.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing = false;
    }

    void me_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    void vid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul.Play();
        musicIsPlaying = true;
    }
    #endregion
    
    #region Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using KeyEventHandler = System.Windows.Input.KeyEventHandler;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace Wpf_AvcTeam
{
public partial class MainWindow : Window
{
    #region Medias
    private Display _avc = new Display();
    MediaPlayer raoul = new MediaPlayer();
    #endregion

    #region Booleans
    private bool videoIsPlaying = false;
    private bool imageIsDisplaying = false;
    private bool backgroundImageIsPlayiing = false;
    private bool textIsDisplaying = false;
    private bool musicIsPlaying = false;
    #endregion

    #region Url
    private string _videoUrl = @"D:\Cédric\Cesi\A2\Projets\DotNetA2\WPF_test_for_HoloAVC\Wpf_AvcTeam\Data\";

    public string VideoUrl => _videoUrl;

    #endregion

    #region Constructor & override
    public MainWindow()
    {
        //ICI FAIRE RECHERCHE DB
        InitializeComponent();
        _avc.Show();
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = false;
        this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
        /*textBox.PreviewKeyDown += EnterClicked;*/
    }

    protected override void OnClosed(EventArgs e)
    {
        base.OnClosed(e);
        Application.Current.Shutdown();
    }
    #endregion


    #region Buttons
    private void disp_btn_Click(object sender, RoutedEventArgs e)
    {
        DisplayText(ref _avc);
    }

    private void open_btn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Filter = "Video files (*.mp4;)|*.mp4|Audio files (*.mp3;*.wav;*.flac)|*.mp3;*.wav;*.flac|Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
        if (openFileDialog.ShowDialog() == true)
        {
            string str = openFileDialog.FileName.Remove(0, openFileDialog.FileName.LastIndexOf(".", StringComparison.Ordinal));

            switch (str)
            {
                case ".mp3":
                case ".wav":
                case ".flac":
                    raoul.Close();
                    raoul.Open(new Uri(openFileDialog.FileName));
                    raoul.Play();
                    break;
                case ".mp4":
                    PlayVideoHolo(ref _avc, openFileDialog.FileName);
                    break;
                case ".png":
                case ".jpg":
                case ".jpeg":
                    DisplayImage(ref _avc, openFileDialog.FileName);
                    break;
            }
        }
    }

    private void play_btn_Click(object sender, RoutedEventArgs e)
    {
        if (!musicIsPlaying)
        {
            raoul.Play();
            musicIsPlaying = true;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Play();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Play();
            _avc.FrontDisplayElement2.Play();
            _avc.FrontDisplayElement3.Play();
            _avc.FrontDisplayElement4.Play();
        }
        play_btn.IsEnabled = false;
        pause_btn.IsEnabled = true;
    }

    private void pause_btn_Click(object sender, RoutedEventArgs e)
    {
        if (musicIsPlaying)
        {
            raoul.Pause();
            musicIsPlaying = false;
        }
        if (backgroundImageIsPlayiing)
        {
            _avc.BackgroundMediaElement.Pause();
        }
        else if (videoIsPlaying)
        {
            _avc.FrontDisplayElement1.Pause();
            _avc.FrontDisplayElement2.Pause();
            _avc.FrontDisplayElement3.Pause();
            _avc.FrontDisplayElement4.Pause();
        }
        pause_btn.IsEnabled = false;
        play_btn.IsEnabled = true;
    }
    #endregion

    
    #region ListBox of videos
    private void ironMan_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"iron_man.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void linkShield_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"link_shield.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void daftPunk_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"playmobil_daftpunk.mp4");
        backgroundImageIsPlayiing = true;
    }

    private void anonymous_listBx_Selected(object sender, RoutedEventArgs e)
    {
        if (imageIsDisplaying)
        {
            HideImages(ref _avc);
        }
        if (textIsDisplaying)
        {
            HideText(ref _avc);
        }
        if (videoIsPlaying)
        {
            HideVideoHolo(ref _avc);
        }
        PlayVideo(ref _avc.BackgroundMediaElement, @"anonymous_mask.mp4");
        backgroundImageIsPlayiing = true;
    }
    #endregion

    #region ListBox of music
    private void tetris_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"tetris.mp3");
    }

    private void wano__listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"wano.mp3");
    }

    private void ultimate_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"ultimate.mp3");
    }

    private void csGo_listBx_Selected(object sender, RoutedEventArgs e)
    {
        PlaySound(ref raoul, @"csgo.mp3");
    }
    #endregion


    #region Videos, Text and Sound Player
    private void PlayVideo(ref MediaElement a, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        a.Source = new Uri(path);
        a.Play();
        a.MediaEnded += new RoutedEventHandler(me_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlayVideoHolo(ref Display x, string a)
    {

        if (imageIsDisplaying)
        {
            HideImages(ref x);
        }
        if (textIsDisplaying)
        {
            HideText(ref x);
        }
        if (backgroundImageIsPlayiing)
        {
            HideVideo(ref x);
        }
        if (x.FrontDisplayElement4.Visibility == Visibility.Hidden)
        {
            x.FrontDisplayElement1.Visibility =
            x.FrontDisplayElement2.Visibility =
                x.FrontDisplayElement3.Visibility = x.FrontDisplayElement4.Visibility = Visibility.Visible;
        }
        x.FrontDisplayElement1.Source = x.FrontDisplayElement2.Source = x.FrontDisplayElement3.Source = x.FrontDisplayElement4.Source = new Uri(a);
        x.FrontDisplayElement1.Play();
        x.FrontDisplayElement2.Play();
        x.FrontDisplayElement3.Play();
        x.FrontDisplayElement4.Play();
        videoIsPlaying = true;
        x.FrontDisplayElement1.MediaEnded += new RoutedEventHandler(vid_MediaEnded);
        pause_btn.IsEnabled = true;
    }

    private void PlaySound(ref MediaPlayer b, string url)
    {
        var path = System.IO.Path.Combine(VideoUrl + url);
        b.Open(new Uri(path));
        b.Play();
        b.MediaEnded += new EventHandler(sound_MediaEnded);
        musicIsPlaying = true;
        pause_btn.IsEnabled = true;
    }

    private void DisplayText(ref Display t)
    {
        HideVideoHolo(ref t);
        HideImages(ref t);
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = textBox.Text;
        textIsDisplaying = true;
    }
    
    private void DisplayImage(ref Display y, string x)
    {
        if (videoIsPlaying)
        {
            HideVideoHolo(ref y);
            
        }
        if (y.image.Visibility == Visibility.Hidden)
        {
            y.image.Visibility = y.image1.Visibility = y.image2.Visibility = y.image3.Visibility = Visibility.Visible;
            imageIsDisplaying = false;
        }
        y.image.Source = y.image1.Source = y.image2.Source = y.image3.Source = new BitmapImage(new Uri(x));
        imageIsDisplaying = true;
    }

    private void HideText(ref Display t)
    {
        t.textBlock1.Text = t.textBlock2.Text = t.textBlock3.Text = t.textBlock4.Text = null;
        textIsDisplaying = false;
    }

    private void HideImages(ref Display f)
    {
        f.image.Visibility = f.image1.Visibility = f.image2.Visibility = f.image3.Visibility = Visibility.Hidden;
        imageIsDisplaying = false;
    }

    private void HideVideoHolo(ref Display f)
    {
        f.FrontDisplayElement1.Visibility =
            f.FrontDisplayElement2.Visibility =
                f.FrontDisplayElement3.Visibility = f.FrontDisplayElement4.Visibility = Visibility.Hidden;
        f.FrontDisplayElement1.Close();
        f.FrontDisplayElement2.Close();
        f.FrontDisplayElement3.Close();
        f.FrontDisplayElement4.Close();
        videoIsPlaying = false;
    }

    private void HideVideo(ref Display f)
    {
        f.BackgroundMediaElement.Close();
        backgroundImageIsPlayiing = false;
    }

    void me_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.BackgroundMediaElement.Position = TimeSpan.FromMilliseconds(1);
        _avc.BackgroundMediaElement.Play();
    }

    void vid_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        _avc.FrontDisplayElement1.Position = _avc.FrontDisplayElement2.Position = _avc.FrontDisplayElement3.Position = _avc.FrontDisplayElement4.Position = TimeSpan.FromMilliseconds(1);
        _avc.FrontDisplayElement1.Play();
        _avc.FrontDisplayElement2.Play();
        _avc.FrontDisplayElement3.Play();
        _avc.FrontDisplayElement4.Play();
    }

    void sound_MediaEnded(object sender, EventArgs e)
    {
        //play video again
        raoul.Position = TimeSpan.FromMilliseconds(1);
        raoul.Play();
        musicIsPlaying = true;
    }
    #endregion
    
    #region Keyhandler
    private void HandleEsc(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
            Close();
    }

    #endregion
    
    }
}
Source Link
Cédric
  • 173
  • 7
Loading