Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Senior Member Tony T's Avatar
    Join Date
    Nov 2009
    Posts
    584

    How to determine if a stream is playing

    How can I determine if a stream is playing? (not if the server is running).
    I want to monitor the stream, and if nothing is playing for 30 minutes, put the computer to sleep.

    I see that the Squeezebox MySQL cache is updated when a new song is played, so I can watch this and if it is not updated in the last 30 minutes, sleep (...or if it has been updated, launch a program like Jiggler to prevent sleep). But this does not work for Internet Streams (plus there must me a better way).

    So, what is the best way to determine if a stream is playing?

    Thanks,
    Tony
     SBTouch ♪ SBRadio ♬

  2. #2
    Senior Member aubuti's Avatar
    Join Date
    Oct 2005
    Posts
    8,354
    Check out the ServerPowerControl plugin, starting with the very long thread in the 3rd Party Plugins forum. It will do exactly what you're asking for: monitor your SBs and send a suspend, hibernate, or shutdown command to the server computer after a user-specified period of SB inactivity. It can even optionally switchover to mysb.com before suspending the server. And if you're looking to roll your own custom suspend function, Gordon has probably worked out the details you need.

  3. #3
    Senior Member Tony T's Avatar
    Join Date
    Nov 2009
    Posts
    584
    I did, but it is overkill for my needs.
    All I need to know is how to determine that a player is playing and I can use a simple launchd to monitor it and act accordingly.
    Tony
     SBTouch ♪ SBRadio ♬

  4. #4
    Senior Member aubuti's Avatar
    Join Date
    Oct 2005
    Posts
    8,354
    Quote Originally Posted by Tony T View Post
    All I need to know is how to determine that a player is playing and I can use a simple launchd to monitor it and act accordingly.
    I think Gordon answers that in the thread, but lord knows which of the 100+ pages....

  5. #5
    Senior Member Tony T's Avatar
    Join Date
    Nov 2009
    Posts
    584
    Thanks, I'll just post a question in that thread.
    Tony
     SBTouch ♪ SBRadio ♬

  6. #6
    Senior Member Tony T's Avatar
    Join Date
    Nov 2009
    Posts
    584
    Quote Originally Posted by aubuti View Post
    I think Gordon answers that in the thread, but lord knows which of the 100+ pages....
    Found it (I just searched for 'play') http://forums.slimdevices.com/showpo...postcount=1352

    I can use the CLI to test if any of my players are in mode: 'play', and if so, I'll run Jiggler to keep my server from sleeping. I can do this with a bash script run every 9 minutes with launchd
    Last edited by Tony T; 2010-07-07 at 18:41.
    Tony
     SBTouch ♪ SBRadio ♬

  7. #7
    Senior Member Tony T's Avatar
    Join Date
    Nov 2009
    Posts
    584
    For a Mac, the following script will determine if a player is in play mode, and if so, move the mouse to prevent the Mac from sleeping:

    Code:
    #!/bin/bash
    
    playerCount=$(printf "player count ?\nexit\n" | nc localhost 9090 | cut -d ' ' -f 3)
    while [ $playerCount -gt 0 ];
    do
    	let playerCount--
    	playerID=$(printf "player id "$playerCount" ?\nexit\n" | nc localhost 9090 | cut -d ' ' -f 4 | sed 's/%/%%/g')
    	playermode=$(printf "$playerID mode ?\nexit\n" | nc localhost 9090 | cut -d ' ' -f 3)
    	if [ "$playermode" = "play"  ]  ; then
    		python <<-END
    		import time
    		from Quartz.CoreGraphics import *
    		def mouseEvent(type, posx, posy):
    		        theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
    		        CGEventPost(kCGHIDEventTap, theEvent)
    		def mousemove(posx,posy):
    		        mouseEvent(kCGEventMouseMoved, posx,posy);
    		ourEvent = CGEventCreate(None);			
    		currentpos=CGEventGetLocation(ourEvent);		
    		mousemove(10,10);
    		time.sleep(1);    # delay so that you can see the mouse move.  Can be removed (along with import time)
    		mousemove(int(currentpos.x),int(currentpos.y));
    		END
    		break
    	fi	
    done
    Run with launchd, and match the time to the sleep setting in the Energy Saver System Preferences (i.e., if set to sleep after 10 minutes of inactivity, set launchd to run every 9 minutes (540 seconds) [Edit: With Lion, for some unknown reason, I had to change the time to 1 minute (60 seconds)]
    Name the following something descriptive (i.e. com.tony.MoveMouse.plist) and place in $HOME/Library/LaunchAgents/ and the above script in your Scripts directory
    (...and change Users/Tony to your user name) Also, you must log-out and back-in for launcd to take effect.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>Label</key>
    	<string>com.tonyt.MoveMouse</string>
    	<key>ProgramArguments</key>
    	<array>
    		<string>/Users/Tony/Library/Scripts/Jiggle.sh</string>
    	</array>
    	<key>StartInterval</key>
    	<integer>60</integer>
    </dict>
    </plist>
    Last edited by Tony T; 2011-08-15 at 16:28. Reason: added mouse move, no need for Jiggler
    Tony
     SBTouch ♪ SBRadio ♬

  8. #8
    Banned
    Join Date
    Feb 2008
    Location
    flat rock community, ga
    Posts
    2,169

    Hey Tony T: I like the Vaughn Bode

    p

  9. #9
    Senior Member Tony T's Avatar
    Join Date
    Nov 2009
    Posts
    584
    Are you referring to "Opus"? (that's Berkeley Breathed)
    Tony
     SBTouch ♪ SBRadio ♬

  10. #10
    Senior Member
    Join Date
    Mar 2008
    Posts
    112
    Just found a bug with my Snow Leopard standard install where the nc localhost command in the script above didn't returned anything so, $playerCount stayed empty all the time. Changing localhost to the IP address of the server fixed that. I know that localhost must work and can be adjusted but just FYI as again, this was a SL install out of the box, so may happen to others..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •