Trying to pause whilst running mplayer from webserver - mplayer

Hi i am creating my own user interface using python.
In this i currently run mplayer from a click with nohup (so as not to mess up the server running), what i would like to do is add a pause button.
Is this possible when running nohup or is there a better way to do it?
so trying
os.system("nohup mplayer file.mp3 &")
does not allow a pause as far as i could find.
then;
os.system("rm /tmp/mplayer")
os.system("mkfifo /tmp/mplayer")
os.system("nohup mplayer -slave -input file=/tmp/mplayer file.mp3 &")
My pause button is then created using;
os.system("echo pause > /tmp/mplayer") ##click again to unplay
works if typed in new terminal but kills my webserver whilst playing. So does not work from webserver.
Currently working with Flask/Python and jinja templates.
Many thanks

Is there any specific reason why you are not using the python-mplayer wrapper to control mplayer from python? This module is pretty complete and gives you control over the playback functions including pausing.
EDIT:
for non-standard mplayer binary location introspection method may need to be called (based on wiki entry from official page.
from mplayer import Player
# First, specify the correct path to the MPlayer executable
Player.exec_path = '/actual/path/to/the/mplayer-bin'
# Then, manually call the introspect() class method
Player.introspect()
# Since autospawn is True by default, no need to call player.spawn() manually
player = Player()
# Play a file
player.loadfile('/path/to/file.mkv')
# Pause playback
player.pause()

Related

Run a code continuously in background in cocoa

I've been using Swift-Keylogger as a command-line program.
I thought of making a UI for it as I have started mac development recently.
As it is a command-line program, the author used RunLoop.current.run() in-order to run the keylogger continuously.
Now the problem is I can't use RunLoop.current.run() because it blocks the UI.
I have looked into GCD and it only runs a piece of code. But I want to run it continuously. I saw some additional articles about running continuously but I found running code continuously after every 'n' specified time by using Timer.
So, how can I replace the RunLoop.current.run() which has same behaviour without blocking UI?
UPDATE: 05/07/2018
To start and stop the keylogger from the UI, check this issue from GitHub
UPDATE: 18/01/2018
Some guy approached me with same requirement as yours. After some discussion and trial and error method, he found a solution.
1) Just comment out the RunLoop.main.run() line in the keylogger code.
2) Now disable the app sandbox. If you want to enable the app sandbox, then add this entitlement com.apple.security.device.usb = YES.
Original: 18/03/2017
I also searched for it a lot in the beginning when I'm writing my keylogger. After a day I gave up.
I use Process in swift to run the keylogger from my UI.
The way I do is:
Do the necessary modifications in keylogger source like the path of files/folders.
Compile the keylogger source.
Drag the keylogger to your project in your Xcode and check copy if needed.
The executable is in resources folder inside your .app.
Run the executable using Process class and launch() to start the executable/ your keylogger.
You should terminate the created process, otherwise the keylogger will be running in the background. To stop the keylogger, use terminate() on Process variable.
Code:
let pathToKeylogger = Bundle.main.resourcePath! + "/Keylogger" // path to keylogger executable
keylogger = Process() // You need to declare this variable at class-level because you need to have the variable later to terminate it.
keylogger.launchPath = pathToKeylogger
keylogger.launch()
To Terminate:
keylogger.terminate()
Edit: 18/03/2017
Try to quit your app normally i.e., either clicking quit in menu bar or in the dock instead of pressing stop button in Xcode. I think you are pressing stop in Xcode.

Binding specific tracks to hotkeys in foobar2000 possibly via autohotkey

I am looking for a way to attach hotkeys to specific tracks in foobar2000. I havent found a way to do it directly through foobar. Ive been trying to write down an autohotkey script which would skip songs until foobars window title matches destined tracks title, but ive been failing so far. If you have an idea on how to do this please help.
First disable this
Library=>Configure=>Shell Integration=>disable "Bring to front when adding new files
Then enable this
Playback=>Playback follows cursor
Then use this
^F1::Run,C:\MusicPlayer\foobar2000.exe /add /immediate "C:\path\to\song.mp3" /play
I am looking for a way to attach hotkeys to specific tracks in foobar2000. I havent found a way to do it directly through foobar
Actually, there is a way
We use the ability of foo_run to bind certain commands to a (global) shortcut.
Additionally we need foo_cmd_playlist to switch to the correct playlist because the used command context_command:play <path_to_mp3> works only if the corresponding playlist is active. Otherwise your track will be appended to the end of the active playlist or send to a new one according to your settings
How to set up
Download & install two foobar2000 plugins foo_run and foo_cmd_playlist
Under Preferences » Tools » Run services add a new entry for each track you need a shortcut. Enter a proper name as label
Under path: you enter
foobar2000 /playlist-activate:"Radio" /context_command:play http://listen.radionomy.com/themashupradio
/playlist-activate:"Radio" is where you define the playlist which has your desired track.
If you have a global playlist with all music in one, just take this playlist and you're fine
/context_command:play http://listen.radionomy.com/themashupradio is the place where you enter the full path to your mp3 (or online stream like my example)
At last, we set up a custom shortcut for our new entry under Preferences » Keyboard Shortcuts
All hail to the fb2k
Foobar2000 supports command line parameters. Simply passing the path of the mp3 file to foobar2000.exe works. Below uses the hotkey Ctrl + F1
^F1:: Run, %comspec% /c "C:\MusicPlayer\foobar2000.exe "C:\path\to\song.mp3"",, Hide

How to run the code without the GUI

I have a rather long perltk code in my hand and I would like to run the simulation in a batch mode (without using the GUI). e.g. I would like to run it with script like "myprog.pl -b" in stead of setting all the parameters in the GUI and click buttons.
My current method is using a separated XML file for config and the function "after" which means the GUI will pop-out and start the simulation then exit after sometime. It is now working, but I have a question: is there a better way solve this problem? Is that possible to have the GUI shown in the background (so we wont see it) in stead of pop-out?
Change the program so it is accessible from both a graphical and command-line interface. Factor out its real functionality into subroutines.
Run the program in an xvfb so that no window is shown on the main display.
Configure the window manager to always start instances of this program minimised and/or with a 0x0 size.

How can I script GNU Screen to start with a program running inside of it so that it does not exit the session on program completion?

How can I script GNU Screen to start with a program running inside of it so that it does not exit the session when the program completes?
I want to run an interactive program as a daemon, if I manually start screen and then launch this program inside of it everything works just as I want. If the program exits or crashes the screen session remains and I can go look at it to see what just happened. However, if I start the program with a simple screen launch then it does run inside of screen but when the program exits the screen session ends and any output from the program is lost.
So screen –dmS serverName serverApplication does not work for my scenario. I did think about making a script which launches the program I want to run & then sleeps forever, I could then launch the script at the same time as screen and should get the effect I am after but it seems rather an untidy way to do things and I am sure there must be something more elegant.
I have read quite a few screen tutorials and trawled through the man page but nothing leaps out at me as the right way to do this. I did try –X but that is for screen commands, not for running commands inside the screen session... Any suggestions will be very much appreciated; I am even happy to use something other than GNU Screen if there is a better tool for use in scripting but please give me an example where possible.
(Side note: The two things I will be running with this are a minecraft_server and a mythtv_backend. My plan was to launch these from a chron job at boot via some ruby/bash script)
First, you'll want to start a daemon screen session just running your default shell:
$ screen -dmS "serverName"
Then, send your command to that shell using screen's stuff in combination with -X:
$ screen -S "serverName" -p 0 -X stuff "serverApplication$(printf \\r)"
The -p is important for telling screen into which window within that session to stuff the command. In this case, it's the only available window, 0, but if you don't specify that, for some odd reason your command will go nowhere. The $(printf \\r) sends a 'Return' keystroke. A regular \n might work in its place, but I've read that's shell-dependent. The newline character does not work in bash; I can vouch for that.
Here's another cool trick. If you want to then make another screen window within that session, you can:
$ screen -S "serverName" -X screen
Now you can send commands to that one using the same syntax as above, but with -p 1. Lots of fun.

Finding event handlers in source trees

So, I'm trying to implement a looping mode in the totem movie player. I would like to do this by adding a checkbox under "Edit" that turns looping on.
I'm trying to figure out what code gets called when "Edit" and the "Shuffle Mode" option under it is clicked. Is there any easy way to find where the appropriate event handler is?
My usual method of code reading (stepping through it with the debugger) didn't work because this is a GUI program, and as soon as you get to the main loop it doesn't stop until there's a breakpoint, and where to put the breakpoints is basically what I'm trying to find out.
I've been using Netbeans for this, and I should note that I can't use Eclipse.
Thank you.
The UI for Totem and the callback names for each element defined in the GtkBuilder file, data/totem.ui.
http://git.gnome.org/browse/totem/tree/data/totem.ui
This file says that the handler for the "Shuffle Mode" action is shuffle_mode_action_callback. Then you can use grep:
grep -r shuffle_mode_action_callback totem-git/src
The result of this command indicates that this function is defined in src/totem-menu.c.