Hi everyone,
in this article, I write a minimal script in python to read and show random videos (mp4,etc…) from your raspberry . This script use omxplayer.
#!/usr/bin/env python# -*- coding: utf-8 -*-import osimport randomimport subprocess#from subprocess import Popenpath = ‘my directory‘files = os.listdir(path)n = len(files)print(‘Element found: ‘ + str(n))for file in files:print(file)#os.system(‘omxplayer -b -o local “‘ + path + ‘/’ + files[rand] + ‘”‘)#omxp = Popen([“omxplayer”,”-b”,”-o”,”local”, path + “/” + files[rand]])while True:rand=random.randint(0,n-1)print(‘Element random select: ‘+ files[rand])subprocess.call([“omxplayer”,”-b”,”-o”,”local”, path + “/” + files[rand]])
#!/usr/bin/env python# -*- coding: utf-8 -*-import osimport randomimport subprocessimport sys#from subprocess import Popenpath = sys.argv[1]files = os.listdir(path)n = len(files)print(‘Element found: ‘ + str(n))for file in files:print(file)#os.system(‘omxplayer -b -o local “‘ + path + ‘/’ + files[rand] + ‘”‘)#omxp = Popen([“omxplayer”,”-b”,”-o”,”local”, path + “/” + files[rand]])while True:rand=random.randint(0,n-1)print(‘Element random select: ‘+ files[rand])subprocess.call([“omxplayer”,”-b”,”-o”,”local”, path + “/” + files[rand]])