Calling g_Player.Play from timer elapsed event not working (1 Viewer)

devo

Retired Team Member
  • Premium Supporter
  • September 2, 2004
    215
    0
    Canada
    I have a timer elapsed event calling Player.g_Player.Play but it doesn't seem to fully work.

    I've verified that the player works just calling Play from a button but when this is called from a TimerElasped event it doesn't work. It seems to stall.

    Here is the output from the log:

    11/09/2004 1:01:35 PM Player.Play(http://64.236.34.67:80/stream/8022)
    11/09/2004 1:01:35 PM Loading external players plugins
    11/09/2004 1:01:35 PM found plugin:MediaPortal.FoobarPlugin.FoobarPlugin in plugins\ExternalPlayers\FoobarExternalPlayer.dll
    11/09/2004 1:01:35 PM player:Foobar2000. author: int_20h
    11/09/2004 1:01:35 PM found plugin:MediaPortal.WinampPlayer.WinampPlugin in plugins\ExternalPlayers\WinampExternalPlayer.dll
    11/09/2004 1:01:35 PM player:Winamp. author: int_20h

    Any help would is appreciated.
     

    devo

    Retired Team Member
  • Premium Supporter
  • September 2, 2004
    215
    0
    Canada
    • Thread starter
    • Banned
    • #2
    steping through the code it makes it to this line then I can't step past it.

    Line 63: m_player = new AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer();

    in AudioPlayerWMP9.cs

    no exception happens though.
     

    Mars Warrior

    Portal Pro
    August 26, 2004
    158
    2
    Airy Crater, Mars
    Home Country
    Might it be that the calls are made in a different context?

    I don't know how you handle the timer event and call the Play method. Is it from that timer event callback procedure, main program, UI dialog...

    Just guessing ;)
     

    devo

    Retired Team Member
  • Premium Supporter
  • September 2, 2004
    215
    0
    Canada
    • Thread starter
    • Banned
    • #4
    Mars Warrior said:
    Might it be that the calls are made in a different context?

    I don't know how you handle the timer event and call the Play method. Is it from that timer event callback procedure, main program, UI dialog...

    Just guessing ;)

    Here is the event code

    Code:
    public void OnTimer(Object sender, ElapsedEventArgs e)
    		{
    			if(sender == _AlarmClock)
    			{
    				GUISpinControl ctlHour = (GUISpinControl)GetControl((int)Controls.CONTROL_ALARMTIMEHOUR);
    				GUISpinControl ctlMinute = (GUISpinControl)GetControl((int)Controls.CONTROL_ALARMTIMEMINUTE);
    	
    				DateTime dtNow = DateTime.Now;
    			
    				if( dtNow.Hour == ctlHour.Value && dtNow.Minute == ctlMinute.Value)
    				{
    					_AlarmClock.Enabled = false;
    					Player.g_Player.Play(_SongPath);
    					GUIControl.SetControlLabel(GetID, (int)Controls.CONTROL_LABELSONGPATH,g_Player.Playing.ToString());
    				}
    			}
    			
    		}
     

    Mars Warrior

    Portal Pro
    August 26, 2004
    158
    2
    Airy Crater, Mars
    Home Country
    Aha. If hitting play from the control does work, than it might indeed be some kind of context problem.

    You might check out the Control.BeginInvoke Method (Delegate, Object[]) and EndInvoke methods which:

    The delegate is called asynchronously, and this method returns immediately. You can call this method from any thread, even the thread that owns the control's handle. If the control's handle does not exist yet, this method searches up the control's parent chain until it finds a control or form that does have a window handle. If no appropriate handle can be found, BeginInvoke will throw an exception. Exceptions within the delegate method are considered untrapped and will be sent to the application's untrapped exception handler.

    Note The BeginInvoke method calls the specified delegate back on a different thread pool thread. You should not block a thread pool thread for any length of time.
    Note There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke, and CreateGraphics. For all other method calls, you should use one of the invoke methods to marshal the call to the control's thread.


    Altough I can't say for sure that it is INDEED a context problem, but if it is the BeginInvoke should solve it ;)
     

    devo

    Retired Team Member
  • Premium Supporter
  • September 2, 2004
    215
    0
    Canada
    • Thread starter
    • Banned
    • #6
    thanks for all your help.... it seems I was using a server timer from System.Timers.Timer namespace. I switched this over to a windows forms timer
    System.Windows.Forms.Timer and it all works great now!!

    On with the coding now :)
     

    Mars Warrior

    Portal Pro
    August 26, 2004
    158
    2
    Airy Crater, Mars
    Home Country
    devo said:
    thanks for all your help.... it seems I was using a server timer from System.Timers.Timer namespace. I switched this over to a windows forms timer
    System.Windows.Forms.Timer and it all works great now!!

    On with the coding now :)
    So indirectly some kind of (thread) context problem. Well get on with the coding!
    And BTW, for what will it be used??
     

    devo

    Retired Team Member
  • Premium Supporter
  • September 2, 2004
    215
    0
    Canada
    • Thread starter
    • Banned
    • #8
    Mars Warrior said:
    devo said:
    thanks for all your help.... it seems I was using a server timer from System.Timers.Timer namespace. I switched this over to a windows forms timer
    System.Windows.Forms.Timer and it all works great now!!

    On with the coding now :)
    So indirectly some kind of (thread) context problem. Well get on with the coding!
    And BTW, for what will it be used??

    Ya exactly, I was trying a few different things like creating a new worker thread but that didn't work either. I am glad it works now though.

    I am working on an alarm plugin. I thought it would be a good way to get my hands dirty with the project and learn the architecture.
     

    Users who are viewing this thread

    Top Bottom