Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If - a media player exists?
#1
Guys do you have any idea any idea on how to write a condition to check whether a media player exists (I'm only curious for the most part)? When I say media player, it is an application that can be controlled with media shortcuts from the keyboard. Example: Groove & Spotify.

Or should I just check for every single application? Also, how do I check if an application is running at all?
Reply
#2
psutil can get info on running processes in a cross platform way: http://psutil.readthedocs.io/en/latest/

Any program can have events bound to those keys, just because they're "media" keys doesn't mean only media programs will use them. Just like text editors aren't the only programs which might use the "t" key. And then there's configurable options... vlc, for example, lets you bind whatever key you want to whatever function you want, so the media "next" button could open/close your playlist instead of... skipping to the next track.

And then, of coarse, a new program might come out which uses those keys.

So the first thing you should ask yourself, is what it is you want to handle. What do you want to do about programs which don't exist yet that might use those keys? What about non-media programs using them?
Reply
#3
As mention bye @nilmao so is psutil nice to use.
Here a example i have given before,also use schedule.

notepad or could be any other process running get check bye iterate over all process running process_iter(),
if notepad is not running start it,if already running do nothing.
This check is now done every 10-sec.
import schedule
import time, os
import psutil
 
def check_process():
    PROCNAME = "notepad.exe"
    for proc in psutil.process_iter():
        if proc.name() == 'notepad.exe':
            return True
    else:
        return False
 
def check_run():
    if check_process():
        print('Notepad is running')
    else:
        print('Notepad in not running')
        print('Start <notepad.exe>')
        os.startfile("notepad.exe")
 
schedule.every(.10).minutes.do(check_run)
while True:
    schedule.run_pending()
    time.sleep(1)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How would I be able to detect a media player app playing a video. phpjunkie 2 591 Oct-16-2023, 02:09 PM
Last Post: phpjunkie
  Python & Windows Media Player Extra 9 4,996 Apr-05-2022, 10:34 PM
Last Post: Extra
  Adding variable to Python code - media sentiment analysis Marietje 3 2,569 May-25-2021, 05:15 PM
Last Post: jefsummers
  Python - Import file sequence into Media Pool jensenni 1 2,152 Feb-02-2021, 05:11 PM
Last Post: buran
  Open windows media player minimised TamP 1 2,238 Aug-02-2020, 08:40 PM
Last Post: Larz60+
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,167 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  MEDIA ROOT ionezation 1 2,197 Mar-29-2019, 02:43 PM
Last Post: ichabod801
  Script for media content and redirect in to a file puneet102 0 2,354 May-22-2018, 12:06 PM
Last Post: puneet102
  Pyglet Media: unjustifiable memory usage hbknjr 4 4,610 Aug-20-2017, 02:08 AM
Last Post: hbknjr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020