I would need two things in vlc that I want to control from a Python script. First is to open a network stream, add the stream address as a url in it and play it. (This might be skippable)
The second thing is to take a snapshot at a specific time and use that picture. As I saw the different kind of libraries and modules, they can only things like play, pause, rewind a video.
Can anybody help me with this one?
Thanks in advance!
You can use os.chdir(path) and os.system(command)
Find where your vlc executable (.exe) is, and store the path in a variable.
Then you can use os.system to execute a given command.
Here you see a list of possible command-line options for VLC
Example code:
import os
vlc_path = "C:\path\to\vlc"
net_stream = "http://host[:port]/file" # You can use other protocols too
os.chdir(vlc_path)
os.system(f"vlc {net_stream}")
Related
import time
import subprocess
from pyvda import AppView, get_apps_by_z_order, VirtualDesktop, get_virtual_desktops
#clockify
subprocess.Popen("C:/Program Files/Clockify/ClockifyWindows.exe")
current_window = AppView.current()
target_desktop = VirtualDesktop(7)
current_window.move(target_desktop)
VirtualDesktop(7).go()
trying to load specific programs to specific desktops in windows 11; so, my "clockify" app loads on the desktop "clock" and blender loads on the blend desktop so on so on.
cannot find any docs for this mofo, but pieced together what's above.
it would be awesome to:
a) check if a virtual desktop exist, and create it, incase of accidental deletion.
but really what I need is a way to specify the "current window". right now (i'm assuming python sees the that as whatever window is active as the current window); I have to put the sleep timer inbeteen loading programs, which is fine.
b) need a way to specify what window as active, then i can tie that to the appropriate desktop and maybe load them all at once to save time
#still a newb and no formal training. and alot of aconyms confuse me, and obvious assumptions may not be obvious to me.
cheers,
-mda
I have a .exe program that is converting an AGS file to an Excel file.
I have a lot of files to convert so I'm wondering can I automate this with Python? The convert-program only requires 2 locations, one for the input and one for the output, see the picture.
With Python I'm albe to start the program with the following code, but is it possible to pass the 2 path's and click Export.
import subprocess
path = r'C:\Program Files (x86)\AGSToExcel.exe'
#Start the programs
subprocess.call([path])
#other locations
path_ags = r'C:\Users\X\Documents\AGS_file1.ags'
path_excel = r'C:\Users\X\Documents\Book1.xls'
I'm fairly new with package subprocess so I have not a clue if this is even possible.
You can probably use pyautogui to click and type if needed.
You can see a simple example here.
PyAutoGUI EXAMPLE
I know how to open a program from python, using the webbrowser module.
My question is this: how do I get it to open full screen?
At the moment I have this code:
import webbrowser
webbrowser.open("file.txt")
But it still opens Restored Down.
Please help!
Given the documentation, the webbrowser module does not have this capability at all.
This is not very surprising since you don't know what kind of device you are operating on, and it might not even have a graphical display!
What I would try is the following:
Use browser = webbrowser.get(SOME_BROWSER) to query which browsers are available.
Launch the browser using browser-specific command line arguments. You might be able to to do browser.args.append(FULLSCREEN_ARGUMENT) and then call browser.open_new(URL) instead of launching the browser manually using e.g.
the subprocess module.
I'm currently writing a program which needs to check if a program is open before deciding to switch to it or open a new one. For example, a chrome short cut should check if chrome is already open. If it isn't then it should open a new chrome window but if it is then it should just show the existing chrome window/tab. Is there a way to write a function to do this?
Thanks in advance.
To check if a program is open I would suggest a library named psutil.
The switch of the window is more complicated and depends on the OS, for example in Windows you have to create (or get) an handle for that window and then call the OS API to change it, this is simply made using win32gui, as you can see here.
Any ideas about controling windows media player in Python? I found the following code on the net which runs fine but no audio is played. am using win7 64 bit machine
# this program will play MP3, WMA, MID, WAV files via the WindowsMediaPlayer
from win32com.client import Dispatch
mp = Dispatch("WMPlayer.OCX")
#tune = mp.newMedia("./SleepAway.mp3")
tune = mp.newMedia("./plays.wav")
mp.currentPlaylist.appendItem(tune)
mp.controls.play()
raw_input("Press Enter to stop playing")
mp.controls.stop()
As I have mentioned in comments, I have had an identical problem. I tried a ridiculous number of different approaches. None of them really worked, so I was stuck using os.startfile to open windows media player to play my sound files. However, just today I had an idea which has led to an alternative solution. It is a bit hack-ish, but it works. Technically I still open windows media player with this approach, but I do so using subprocess, and thus I can use the greater control over the process allowed by that to supress the window. This makes it seem like it plays without a secondary application. Why I had to do something so bizarre to get a simple result I have no idea, but it is the only thing that worked. Here is my code for it if you want.
import subprocess
import threading
def windowsmedia(filename):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
a = subprocess.call('C:\\Program Files (x86)\\Windows Media Player\\wmplayer.exe /play /close "C:/Users/Student/Documents/notes/file.mp3"',startupinfo=startupinfo)
def startmp3(filename):
mythread = threading.Thread(target=windowsmedia,args=[filename])
mythread.start()
time.sleep(15) #You might want to extend this... I just give it 15 seconds to complete before killing the process. It shouldn't be too hard to read the exact length from the file and wait that, or add an interrupt, but that was somewhat unnecessary for my purposes.
pkill("wmplayer") #This is a function of my own but it basically just kills the process. It shouldn't be too hard to reproduce.
Again it is truly regrettable that I had to do something so weird for just playing a sound but as far as you have described it this is the same issue and I hope this helps.
Thought, it might help others who are still facing this issue.
All you had to do is to call PlayItem() API after Play().
from win32com.client import Dispatch
from time import sleep
mp = Dispatch("WMPlayer.OCX")
tune = mp.newMedia("./plays.wav")
mp.currentPlaylist.appendItem(tune)
mp.controls.play()
sleep(1)
mp.controls.playItem(tune)
raw_input("Press Enter to stop playing")
mp.controls.stop()
It helps me to use Windows Media COM. When I tried it, I need to make 2 small modification to make it working in Python Flask.
CoInitialize to make it single thread i.e. pythoncom.CoInitialize() and pythoncom.CoUninitialize()
PumpWaitMessage to keep MediaPlayer working i.e while mp.PlayState != 1: pythoncom.PumpWaitingMessages()