| 
    
     | 
       
        | Author |  |  
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          While working on some new TTS reminders, I wanted to be able to pause Winamp if it was playing and a reminder was to be spoken. This turned into a few hours of research and playing around to get this macro. It communicates with Winamp via Windows Messaging and updates a Global Variable (WINAMP STATUS) with the status code: -1=Winamp not loaded, 0=Stopped, 1=Playing, 3=Paused.
           | Posted: October 03 2004 at 13:13 | IP Logged |   |  
           | 
 |  
 insert into macroheader values ('TEST WINAMP','WINAMP STATUS',0,0,1);
 insert into macrodetail values ('TEST WINAMP',1,15,'[LOCAL1]',NULL,'ph_findwindow("Winamp v1.x",0)',0);
 insert into macrodetail values ('TEST WINAMP',2,16,'',NULL,'if([LOCAL1] = 0, 1, 3)',0);
 insert into macrodetail values ('TEST WINAMP',3,10,'WINAMP STATUS',NULL,'-1',0);
 insert into macrodetail values ('TEST WINAMP',4,16,'',NULL,'999',0);
 insert into macrodetail values ('TEST WINAMP',5,10,'WINAMP STATUS',NULL,'ph_sendmsg( [LOCAL1], 1024, 0, 104)',0);
 
 
 You could, with a case statement, also use text instead of numbers...
 
 case ( {WINAMP STATUS} WHEN -1 THEN "Not Loaded" WHEN 0 THEN "Stopped" WHEN 1 THEN "Playing" WHEN 3 THEN "Paused")
 |  
        | Back to Top |       |  
        |  |  
        | dmoreno Newbie
 
  
  
 Joined: February 15 2002
 Location: United States
 Online Status: Offline
 Posts: 31
 | 
          Is there a way to get powerhome to recognize or detect a song change in a playlist?
           | Posted: February 25 2006 at 08:29 | IP Logged |   |  
           | 
 |  |  
        | Back to Top |     |  
        |  |  
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          This is something that needs to come from Winamp. Dave has mentioned that he may look at writing a Winamp plugin for this and some other functions.
           | Posted: February 25 2006 at 09:33 | IP Logged |   |  
           | 
 |  
 As an update, the latest version of PH supports Winamp directly with ph_winampinfo and ph_winampctrl.
 
 The first post in this thread is now reduced to ph_winampinfo ( "status", 1). This command returns "playing", "paused", "stopped", and "not running". After this is executed, LOCAL1 will contain "0". If an error occurs, then LOCAL1 will contain "1". If Winamp is not running, then LOCAL1 will contain "2". If the command is not recognized, then LOCAL1 will contain "3".
 |  
        | Back to Top |       |  
        |  |  
        | dmoreno Newbie
 
  
  
 Joined: February 15 2002
 Location: United States
 Online Status: Offline
 Posts: 31
 | 
          TonyNo, I think a plugin would be a good idea. Is there a way setup a macro to fire, say every 15 to 30 seconds to poll winamp for a song change?
           | Posted: February 26 2006 at 06:52 | IP Logged |   |  
           | 
 |  
 What I did was create a textbox with current track using the ph_ccmodify function. Couldn't I get the track length from ph_winampinfo and fire a macro then?
 |  
        | Back to Top |     |  
        |  |  
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Until I get the Winamp plugin written, using the ph_winampinfo and ph_winampctrl functions is the best we've got.
           | Posted: February 26 2006 at 10:29 | IP Logged |   |  
           | 
 |  
 Instead of polling every 15 to 30 seconds, I would setup a waiting macro to handle the changes.  You would have to fire this macro when you press play and have to handle situations for when you hit pause, stop, fast forward, etc.  The basic idea would be to wait for the length of the song, wake up, get the current playing song title, wait again, etc.
 
 The wait formula would be something like: ph_winampinfo("tracklen",0) - (ph_winampinfo("trackpos",0) / 1000) + 1
 
 So no matter when the macro was called, it would calculate the total length of the song minus the current position and then add 1 second to make sure you've made it to the next song.
 
 I would think you could make something like this work.
 
 Let me know if you need help.
 
 Dave.
 
 |  
        | Back to Top |       |  
        |  |  
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          That is how my JavaScript works with Browseamp to keep synced. Good solution!
           | Posted: February 26 2006 at 10:35 | IP Logged |   |  
           | 
 |  |  
        | Back to Top |       |  
        |  |  
        | dmoreno Newbie
 
  
  
 Joined: February 15 2002
 Location: United States
 Online Status: Offline
 Posts: 31
 | 
          OK Dave got it to work. The way I did it was getting the track length minus the current position. I used a doctored formula as above to create a timed macro. But every time I click a button it creates a new timed macro.Is there a way to update the existing timed macro, or even kill the existing timed macro before creating a new one.  I looked through the help files and searched the forum, but not finding what I was looking for?
           | Posted: March 02 2006 at 04:27 | IP Logged |   |  
           | 
 |    |  
        | Back to Top |     |  
        |  |  
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          Do you mean Timed Event?
           | Posted: March 02 2006 at 07:49 | IP Logged |   |  
           | 
 |  
 Dave suggested using Wait in a macro, which can be updated (ph_extendmacrowait) or killed (ph_killmacrowait).
 |  
        | Back to Top |       |  
        |  |  
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          I just found a problem with Dave's suggested wait formula. Apparently, the times are returned as a string, so change it to this...
           | Posted: September 04 2006 at 11:16 | IP Logged |   |  
           | 
 |  
 int( number( ph_winampinfo( "tracklen",0)) - ( number( ph_winampinfo( "trackpos",0)) / 1000) + 1)
 |  
        | Back to Top |       |  
        |  |  
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Gosh, I hope Don got this figured out.  I cant believe I missed this.
           | Posted: September 15 2006 at 23:06 | IP Logged |   |  
           | 
 |  
 To kill an existing waiting macro, use the ph_killmacrowait("WAITINGMACROID").  You can also extend the wait time of a currently waiting macro with ph_extendmacrowait.  These functions are documented in the help file.
 
 Good catch Tony.  Yes, the ph_winampinfo function returns a string since depending upon the requested info, it may not be numeric data (PowerHome has no concept of function overloading).
 
 Dave.
 
 |  
        | Back to Top |       |  
        |  |  
        | TonyNo Moderator Group
 
  
  
 Joined: December 05 2001
 Location: United States
 Online Status: Offline
 Posts: 2889
 | 
          I'm finally tracking down an error condition with this that's been plaguing me for a while now.
           | Posted: October 26 2008 at 09:12 | IP Logged |   |  
           | 
 |  
 The problem is that, sometimes, the track position comes back as beyond the track length.
 
 Example:
 Track Length: 285
 Track Pos: 285420
 
 I think this caused an endless loop with my code, but I can't recall for sure. Testing now.
 |  
        | Back to Top |       |  
        |  |  |  |