gilles-chanteperdrix / squeezelite

Automatically exported from code.google.com/p/squeezelite
Other
0 stars 0 forks source link

Feature request: external command on Alsa connect/disconnect #42

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It'd like to specify external commands via command line, which are called on 
Alsa connect and disconnect. I'd like use those commands to turn on and off my 
external amplifier...

Thanks!

Original issue reported on code.google.com by tutm...@gmail.com on 23 Aug 2013 at 9:49

GoogleCodeExporter commented 8 years ago
If you are running on a machine which is also running a the jivelite then this 
could be scripted and there is already a script for enabling/disabling external 
hardware on the CSOS distribution - called TriggerOutput - see 
http://forums.slimdevices.com/showthread.php?98834-Second-project-with-the-Commu
nity-Squeeze

Original comment by trio...@btinternet.com on 23 Aug 2013 at 8:17

GoogleCodeExporter commented 8 years ago
This is a fantastic idea. I've been wanting to do the same thing. Although I 
wonder if there is another way to achieve it.

Original comment by ryan130...@gmail.com on 11 Sep 2013 at 11:49

GoogleCodeExporter commented 8 years ago
I'd also like to be able to do this. I don't have jivelite installed on my pi 
and don't need it's functionality, but I would like to turn my amplifier on and 
off and also, ideally, hijack the squeezebox volume controls to adjust my amp's 
volume via i2c instead of the volume of the squeezelite player.

Anyone have any suggestions?

Original comment by ben.har...@gmail.com on 18 Mar 2014 at 2:30

GoogleCodeExporter commented 8 years ago
I would like that function too to switch my amplifier On/Off without using 
jivelite.
I.e. a command line switch telling squeezelite to write On/Off status to a file.
An other process, that I make, could poll that file and make the IO to Pi's 
GPIO.

Original comment by jan.ande...@get2net.dk on 5 Apr 2014 at 11:23

GoogleCodeExporter commented 8 years ago
This is exactly what I have been looking for.

A Perfect way of achieving this would be to allow hook-scripts, such that you 
can hook on commands which are processed right now, e.g.

OnPlay       - gets executed everytime the play command is issued (beginning of 
each song or if you hit play)
OnConnect    - gets exectued after connect
OnDisconnect - ... after disconnect

Also, it would be great to have access to certain env-variables, lets say the 
current song is 

SQLT_SONG_NAME
SQLT_SONG_DURATION
SQLT_SONG_GENRE
SQLT_SONG_ARTIST

Or so. This way controlling an LCD display is very easy.

I know this is actually easy to implement, but a lot of work to 
maintain....what if the script fails? Should squeezelite stop? What if you have 
infinite loops within the script. The mechanism should be pretty safe.

Whats the authors opinion?

Original comment by nhellw...@gmail.com on 31 Jul 2014 at 12:18

GoogleCodeExporter commented 8 years ago
You should implement this on the LMS server not as part of squeezeplay.  
Squeezeplay has no idea of the name, artist or genre information - this is only 
available from the server.  There are already apis for interfacing to the 
server please look at these.

Original comment by trio...@btinternet.com on 31 Jul 2014 at 8:01

GoogleCodeExporter commented 8 years ago
Hello everyone :)

So I think basically there are two things, which are being discussed here:

1. Song informatin etc
2. Interrupts for ALSA On/Off

I agree, the first one should not be part of squeezelite, but lets come to that 
later.

I have figured out some way to trigger actions on ALSA On and Off. The basic 
idea is to constantly parse the logfile and then use that information to figure 
out whats going on right now. Here is what I did:

1. Turn on all log information you can (all=debug). It might work with less, I 
have not tried so far.

2. Use this script at the bottom. This script parses the logfile and then 
determines if ALSA was attached or not. It works for me on a raspberry pi and 
is super efficient. All you have to do is to put your code instead of "Its On" 
and "Its Off". It will run forever. I have no Idea how big the log files will 
be and if this is going to be a problem, but I will investigate that.

3. Now, if you need Song info and so on, I strongly recommend this project: 
http://code.google.com/p/squeezy/

All right..What do you think??

#!/bin/bash

LOGFILE="/var/log/squeezeslite.log"
BAIT='(output)'

tail -F $LOGFILE | grep --line-buffered -E $BAIT | while read CATCH
do 
    if echo $CATCH | grep -q 'open output'; then
        echo "Its On..."
    elif echo $CATCH | grep -q 'disabling output' $LOGFILE; then
        echo "Its Off..."
    fi
done

Original comment by nhellw...@gmail.com on 29 Aug 2014 at 5:18

GoogleCodeExporter commented 8 years ago
I think you should also consider a script which connects to the server and 
subscribes to player state commands - this will show you when a player is on or 
off and does not rely on squeezelite specific debugs (which may change).

Original comment by trio...@btinternet.com on 31 Aug 2014 at 10:39

GoogleCodeExporter commented 8 years ago
In my case the server is a synology NAS, which I dont want to wake up that 
much, so I prefer a client side method.

Well, I could adjust the script to actually parse the network traffic via 
tcpdump, that way no log file had to be written and it only depends on the 
network commands, which shouldnt change that much. This script could then run 
either on client or server side. I might have a look at it ;)

Original comment by nhellw...@gmail.com on 31 Aug 2014 at 12:10

GoogleCodeExporter commented 8 years ago
Turns out that the tcpdump version uses too much cpu on the pi...guess that 
wont work.

Does anyone know where the server stores the information about the player 
status or is it possible subscribe to a player, as mentioned in the post before?

Original comment by nhellw...@gmail.com on 31 Aug 2014 at 3:27

GoogleCodeExporter commented 8 years ago
Hello,

This is also what I was looking for.

I was wondering to have some news about this Alsa On/Off feature. Is there a 
release planned with this feature soon ?

If not, I can contribute to add this feature in the source code. I'm thinking 
to add a LUA script call in the Alsa On/Off event.

Let me know.

Original comment by wiz...@gmail.com on 24 Jun 2015 at 10:06

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Would be great if you could tell us how you did it.

Original comment by nhellw...@gmail.com on 20 Jul 2015 at 2:45

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Maybe you could post the snippet in the code or provide a patch? Generally, I 
think it should be better to be independent on the script language. In the end, 
its just a file which is executed, so it should not matter whether its Python, 
Perl, Binary or whatever. 

Is that possible in your approach?

Original comment by nhellw...@gmail.com on 20 Jul 2015 at 3:33

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hello,

Here's the path for the current squeezelite version.

Just expand to the source directory and apply the patch in the source directory 
"patch < squeezelite.patch"

Prerequisite package for python is the libpython2.7-dev and liblua2.5-dev for 
lua use.

Then compile with this command: "OPTS=-DNOTIFY_PYTHON make" to integrate the 
python script. use NOTIFY_LUA for working with lua script.

Create the script file, you must have two function defined inside the file. 
respectively connect and disconnect. Each for the alsa caught event.

Feel free to check the squeezelite_notify.py file as example.

add -S flag followed by the script filename when calling the squeezelite 
software. 

Original comment by wiz...@gmail.com on 21 Jul 2015 at 2:29

Attachments:

GoogleCodeExporter commented 8 years ago
Hello,

Here is a new patch version. Some little adjustment :)

Original comment by wiz...@gmail.com on 18 Aug 2015 at 8:54

Attachments: