Aviv
Aviv

Reputation: 466

Can't See The Content Of MediaElement In Window - WPF

I've tried to create a "Connecting To Server" Window. This window is needed to be shown after the Program's Opening splash screen. The window contains a MediaElement only, and in this MediaElement I need to show a .avi file. Inside the .cs file of the Window, I'm Creating Socket, which needs to connect to my server and check for updates. In Addition, I wan't the splash screen to stop displaying the .avi file when the response(from the server) is accepted.

My problem is that the window doesn't show the .avi file. When I replaced the .avi file with mp3 file(for testing..), it performs me the same result.

Generally, My code is looking like this:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.MediaElement.Play();

        ------------------------------
        |  Socket's Code Comes Here  |
        ------------------------------

        if (this.IsUpdateNeeded == true) //IsUpdateNeeded == My Own Variable..
        {
            MessageBox.Show("New Version Is Here !", "New Version Is Here !", MessageBoxButtons.OK, .MessageBoxIcon.Information);
            GoToWebsite();
        }
        else
        {
            MessageBox.Show("You Own The Latest Version", "No Update Is Needed", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        this.MediaElement.Stop();
        this.Close();
    }

can anyone help me to figure it out please?

Upvotes: 0

Views: 508

Answers (1)

grantnz
grantnz

Reputation: 7423

Code to run in another thread (and so not block the main UI thread and stop the video playing)

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    this.MediaElement.Play();

    Task.Factory.StartNew(
        new Action(delegate()
        {
          /*
           * ------------------------------
             Socket's Code Comes Here  |
             ------------------------------
           */

          Dispatcher.Invoke(
                      new Action(delegate()
                      {

                            if (this.IsUpdateNeeded == true) //IsUpdateNeeded == My Own Variable..
                            {
                                       MessageBox.Show("New Version Is Here !", "New Version Is Here !", MessageBoxButton.OK, MessageBoxImage.Information);
                                       GoToWebsite();
                            }
                            else
                           {
                               MessageBox.Show("You Own The Latest Version", "No Update Is Needed", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                           this.MediaElement.Stop();
                           this.Close();   
                      }                
                    ));
                }
            )
        );
    }

Upvotes: 1

Related Questions