ahmad05
ahmad05

Reputation: 458

Can't access media element in the event handler how to set it global?

i have recently started working on C# and i am very amateur at it please any help in the problem decirbed below will b very helpful for me

What i wanted to do is have an access of video_panel in event handler as-well but right now i dont know how to do that i tried to declare media element global and set its value to video_panel but still no use what should i do what i want to is instead of displaying a message pause a video currently playing

namespace Play_pause
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

  static   int index = 0;
  static  System.Timers.Timer aTimer = new System.Timers.Timer();
    public MainWindow()
    {
        InitializeComponent();
       video_panel.Play();

        // Hook up the Elapsed event for the timer.
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

        // Set the Interval to 2 seconds (2000 milliseconds).
        aTimer.Interval = 2000;

        aTimer.Start();




    }

    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {



        index++;
        if (index %2==0)
        {
            MessageBox.Show("Can't access media element in the event handler/n how to    
            set it global?");




        }

    }    
}

}

Upvotes: 0

Views: 331

Answers (1)

Florian Gl
Florian Gl

Reputation: 6014

Read the answers here again, they show how to make a variable global.

But this wont solve your problem. Since your OnTimedEvent-method is static, you can access only static variables. I dont think your OnTimedEvent should be static, so try to remove the word "static" and now you can acess global variables (e.g. your video_panel).

Upvotes: 1

Related Questions