Showing posts with label omxplayer gui. Show all posts
Showing posts with label omxplayer gui. Show all posts

Saturday, September 26, 2015

Playing OMXPlayer from a Python Program -Raspberry Pi

I have bought raspberry pi and is much excited about doing cool stuffs with it. First of all there is a problem with the vlc player video playing. Yes, being a movie lover I checked the movie player first But vlc was unable to play videos. There are ways you can use vlc but they a re tedious.
So, I switched to omxplayer, a non-graphical command based video player. The video playing with omxplayer is good but you need to write to console everytime.
Here's what I have done do the file browsing and opening automatically in raspberry pi .

All we need to write these type of program where we need use other program or os resources, we need to import the os module. And then use os.sys to execute os commands. So, the program will be something like below -

import os,sys
from Tkinter  import *
from tkFileDialog import askopenfilename
##filename=str(raw_input('@Enter a file name :'))
##os.system('omxplayer -o hdmi /home/pi/Desktop/1.mp4')
class MediaPlayer():
    def __init__(self,root):
        self.playbutton=Button(root,text='Play',command=self.play).pack()
        self.stopbutton=Button(root,text='stop',command=self.stop).pack()
    def play(self):
        filename=str(askopenfilename())
        try:
            os.system('omxplayer -o hdmi %s'%filename)
        except:
            print ("File OPening Problem")
    def stop (self):
        sys.exit()
root=Tk()
cd=MediaPlayer(root)
root.geometry('300x200')

root.mainloop()


Please visit my previous post to learn about os.sys http://cseatglance.blogspot.in/2015/08/how-to-run-os-commands-from-pytohn-idle.html

 The program is self-explanatory and will work but the stop button should work after you do find the command to stop the omxplayer and apply here. Actually you have to find out each omxplayer command e.g. for skip,stop,quit etc and then just write in the os.sys after creating a button and a suitable function for this. You have to also use keyboard or mouse event in your program as once the omxplayer start you can not see your gui music player app.

Feautured Post

Python Trivia Post: enumerate()

Python has a very useful inbuilt function, which is called enumerate(). This is needed whenever you need the numbering of a certain element...