AiRSpectruM
Posts: 5
Joined: Fri Jul 13, 2018 2:20 pm

Running the omxplayer within a python script

Fri Jul 13, 2018 2:32 pm

So I am trying to make a TV controller of sorts. The idea is to have a GUI running on the raspi touchscreen interface and when a button on the GUI is pushed it triggers the command

Code: Select all

omxplayer --display=5 /home/pi/Videos/FireplaceVid.mp4
. The issue I have run into is that I cannot get this to run outside of typing it into the command prompt myself.

I know a bit of code but python is a completely new language to me so any help would be appreciated! :D
I am attaching the code for reference, sorry it is a bit messy:

Code: Select all

from tkinter import *
import tkinter.font
import webbrowser
import sys
import os
from subprocess import Popen

FireplaceVid = ("/home/pi/Videos/FireplaceVid.mp4)")
x = 0
###GUI DEFINITIONS###
win = Tk()
win.title("Test Gui")
myFont = tkinter.font.Font(family = 'Helvetica', size = 24, weight = "bold")


###FUNCTIONS###

def playFireplace():
    ###print("Hello World") ##WORKS
    ###webbrowser.open('https://drive.google.com/file/d/1llSwk5i4ODydMJQeVO7NJm9KF9Ju_LFj/view?usp=sharing') ##KINDA WORKS
    ##os.system ("omxplayer /home/pi/Videos/FireplaceVid.mp4") ##DOES NOT WORK
    #os.system('killall omxplayer.bin') #DOES
    #mxc = Popen(['omxplayer', '-b', FireplaceVid]) #NOT
    #player = True #WORK
    subprocess ('omxplayer /home/pi/Videos/FireplaceVid.mp4') #DOES NOT WORK
    

    #webbrowser.open('https://www.youtube.com/embed/RDfjXj5EGqI?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>')
def playAquarium():
    webbrowser.open('https://www.youtube.com/embed/KUv-8k2Fy_k?rel=0&amp;showinfo=0&amp;start=45" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>')
def playMHTPong():
    print("Pong Sounds")
def gottoweb():
    webbrowser.open('https://google.com')
    



###Widgets###
Fireplace = Button(win, height=6, width=20, borderwidth=2, text = 'Fireplace', font = myFont,)
Fireplace.grid(row=0,column=1)
Aquarium = Button(win, height=6, width=20, borderwidth=2, text = 'Aquarium', font = myFont, command = playAquarium)
Aquarium.grid(row=2,column=1)
MHTPong = Button(win, height=6, width=20, borderwidth=2, text = 'MHTPong', font = myFont, command = playMHTPong)
MHTPong.grid(row=0,column=2)
internet = Button(win, text= 'Internet', font = myFont, command = gottoweb)
internet.grid(row=2,column=2)

AiRSpectruM
Posts: 5
Joined: Fri Jul 13, 2018 2:20 pm

Re: Running the omxplayer within a python script

Fri Jul 13, 2018 3:29 pm

I found my first issue, I had forgotten to call the command when the button was pressed (must've gotten lost somewhere in trying new things) once that was re added I used the

Code: Select all

os.system ("omxplayer --display=5 /home/pi/Videos/FireplaceVid.mp4")
and the video played just fine.

However I noticed that I could not get the video to stop playing, would there be a way to add a button linked to the omxplayer stop command?

Return to “Python”

Who is online

Users browsing this forum: Google [Bot], MikeDS and 15 guests