def video(request): global omx #,qviv global stapwd,setpwd,softPath po = yield from request.post() #print(po) if po['p'] == stapwd: if po['m'] == 'play': #print('video play...') omx = OMXPlayer(softPath+'Videos/'+po['d']+'.mp4',softPath+po['i']) tbody= '{"a":"video","b":"play"}' elif po['m'] == 'stop': omx.stop() tbody= '{"a":"video","b":"stop"}' elif po['m'] == 'pause': omx.toggle_pause() tbody= '{"a":"video","b":"pause"}' else: tbody= '{"p":"error"}' print(tbody) return web.Response(headers='' ,body=tbody.encode('utf-8'))
def video(request): global omx,qviv global stapwd,setpwd,softPath po = yield from request.post() #print(po) #yield from playv(request) if po['p'] == stapwd: if po['m'] == 'play': omx = OMXPlayer(softPath+'Videos/'+po['d']+'.mp4') tbody= '{"a":"video","b":"play"}' while omx._VOF: yield from asyncio.sleep(0.5) qviv=QIV(softPath+'/'+po['i']) elif po['m'] == 'stop': omx.stop() tbody= '{"a":"video","b":"stop"}' qviv=QIV(softPath+'/'+po['i']) elif po['m'] == 'pause': omx.toggle_pause() tbody= '{"a":"video","b":"pause"}' else: tbody= '{"p":"error"}' print(tbody) return web.Response(headers='' ,body=tbody.encode('utf-8'))
def playVideo(fileName, db): try: p = OMXPlayer(fileName) p.toggle_pause() except: print "problem playing video" p = None return p
def run(self): omx = OMXPlayer(self.path, args=self.args) self.player_queue.put(omx) omx.toggle_pause() last_position = 0 wait_time = 10 while True: time.sleep(1) if not omx.is_running(): self.player_queue.get() self.player_queue.task_done() break elif not omx.paused and omx.position == last_position: wait_time = wait_time - 1 if wait_time <= 0: omx.stop() else: last_position = omx.position
def PlayMedia(self, fullpath, tag, unknown1, unknown2, unknown3): print "---" print fullpath print tag f = urllib2.urlopen(fullpath) s = f.read() f.close() print s tree = et.fromstring(s) # get video el = tree.find("./Video/Media/Part") print el.attrib["key"] print "fullpath", fullpath # Construct the path to the media. o = urlparse(fullpath) mediapath = o.scheme + "://" + o.netloc + el.attrib["key"] print "mediapath", mediapath global omx omx = OMXPlayer(mediapath) omx.toggle_pause()
def singleVideoLoop(self, filename): duration = self.getVideoDurationSeconds(filename) fullPath = self.mediaPath + filename print "VIDEO PATH: ", fullPath looper1 = OMXPlayer(fullPath, start_playback=True) looper2 = OMXPlayer(fullPath, start_playback=True) looper2.toggle_pause() looper1Active = True pos = 0 while self.config['repeat'] and playerState == PLAYER_STARTED: if looper1Active: pos = looper1.position else: pos = looper2.position # print "Position: ", pos if pos > duration -2: print "TOGGLING LOOPERS..." # start other looper, wait 3 seconds and reload current looper for next round if looper1Active: looper2.toggle_pause() looper1.stop() time.sleep(1) looper1 = OMXPlayer(fullPath, start_playback=True) looper1.toggle_pause() else: looper1.toggle_pause() looper2.stop() time.sleep(1) looper2 = OMXPlayer(fullPath, start_playback=True) looper2.toggle_pause() looper1Active = not looper1Active time.sleep(0.1) if looper1: looper1.stop() if looper2: looper2.stop()
def video(request): global omx global stapwd, setpwd, softPath po = yield from request.post() if 1: #po['p'] == stapwd: if po['m'] == 'play': #print('video play...') omx = OMXPlayer(softPath + 'Videos/' + po['d'] + '.mp4', softPath + po['i']) tbody = '{"a":"video","b":"play"}' elif po['m'] == 'stop': omx.stop() tbody = '{"a":"video","b":"stop"}' elif po['m'] == 'pause': omx.toggle_pause() tbody = '{"a":"video","b":"pause"}' else: tbody = '{"p":"error"}' print(tbody) return web.Response(headers='', body=tbody.encode('utf-8'))
def singleVideoLoop(self, filename): duration = self.getVideoDurationSeconds(filename) fullPath = self.mediaPath + filename #print "VIDEO PATH: ", fullPath looper1 = OMXPlayer(fullPath, start_playback=True) looper2 = OMXPlayer(fullPath, start_playback=True) looper2.toggle_pause() looper1Active = True pos = 0 while self.config['repeat'] and playerState == PLAYER_STARTED: if looper1Active: pos = looper1.position else: pos = looper2.position # print "Position: ", pos if pos > duration - 2: #print "TOGGLING LOOPERS..." # start other looper, wait 3 seconds and reload current looper for next round if looper1Active: looper2.toggle_pause() looper1.stop() time.sleep(1) looper1 = OMXPlayer(fullPath, start_playback=True) looper1.toggle_pause() else: looper1.toggle_pause() looper2.stop() time.sleep(1) looper2 = OMXPlayer(fullPath, start_playback=True) looper2.toggle_pause() looper1Active = not looper1Active time.sleep(0.1) if looper1: looper1.stop() if looper2: looper2.stop()
import pygame import time from pyomxplayer import OMXPlayer pygame.init() pygame.mouse.set_visible(False) screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN) screen.fill((0,0,0)) done = False player = OMXPlayer('videos/stag.mp4', '-o local') player.toggle_pause() while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True time.sleep(0.01) pygame.quit()
class Player: def __init__(self, video): self.video = video screenWidth, screenHeight = getScreenSize() if sys.platform == 'darwin': self.player = MPlayerX(self.video, screenWidth, screenHeight) else: self.player = OMXPlayer(self.video, screenWidth, screenHeight) self.from_position = video.progress def getUrls(self): if self.video.realUrl == playlistStorage: with open(playlistStorage, 'r') as f: urls = [v.strip() for v in f.readlines() if v.startswith('http')] else: urls = [self.video.realUrl] delta = 0 if int(self.video.progress) > 30: if len(self.video.sections) <= 1: urls = urls delta = int(self.video.progress) else: new_progress, c_idx = self.video.getSectionsFrom(self.video.progress) urls = urls[c_idx:] delta = int(self.video.progress - new_progress) logging.info("urls = %s, delta = %s", urls, delta) return (urls, delta) def getFfmpegCmd(self, ss, inputFile, outputFile): if ss > 30: return 'nice -n 19 ffmpeg -ss %s -i "%s" -ss %s -c copy -bsf:v h264_mp4toannexb -y -f mpegts %s 2>%s.log' \ % (ss - 30, inputFile, 30, outputFile, outputFile) else: return 'nice -n 19 ffmpeg -i "%s" -c copy -bsf:v h264_mp4toannexb -y -f mpegts %s 2>%s.log' \ % (inputFile, outputFile, outputFile) def init(self): # Check the progress and decide the download cmd self.video.playUrl = "/tmp/all.ts" if len(self.video.sections) <= 1: # Unsplitted file if self.video.progress <= 30: urls, delta = self.getUrls() self.video.downloader = MultiDownloader(urls, alternativeUrls=self.video.alternativeUrls) self.video.downloader.getSizeInfo() self.video.download_args = '%s > %s 2>/tmp/cat.log' % (self.video.downloader.getCatCmds()[0], self.video.playUrl) else: self.video.downloader = None self.video.download_args = self.getFfmpegCmd(self.video.progress, self.getUrls()[0][0], self.video.playUrl) else: # Splitted file urls, delta = self.getUrls() self.video.downloader = MultiDownloader(urls, alternativeUrls=self.video.alternativeUrls) self.video.downloader.getSizeInfo() catCmds = self.video.downloader.getCatCmds() ffmpeg_part = "/tmp/ffmpeg_part" p_list = [] download_lines = [] for idx, catCmd in enumerate(catCmds): pname = os.path.join(ffmpeg_part, str(idx)) newFifo(pname) if idx == 0 and delta > 30: download_lines.append("{\n%s | %s\n}" % (catCmd, self.getFfmpegCmd(delta, "-", pname))) else: download_lines.append("{\n%s | %s\n}" % (catCmd, self.getFfmpegCmd(0, "-", pname))) p_list.append(pname) ffmpeg_input = " ".join(p_list) download_args = 'cat %s | ffmpeg -f mpegts -i - -c copy -y -f mpegts %s 2> /tmp/merge.log &\n' \ % (ffmpeg_input, self.video.playUrl) download_args += " && ".join(download_lines) self.video.download_args = download_args def download(self, lock): if self.video.downloader: self.video.downloader.setLock(lock) self.video.downloader.start() def play(self, lock): # New a thread to play self.playThread = Thread(target=self.play_thread, args=(lock,)) self.playThread.daemon = True self.playThread.start() def play_thread(self, lock): with lock: logging.info("Got lock and play now") self.player.play() interval = 0 while self.player.isalive(): time.sleep(1) interval += 1 self.video.progress = self.from_position + self.getPosition() if not imgService.stop and self.video.progress > 0: imgService.end() if interval % 10 == 0: db_writeHistory(self.video) if imgService.stop: imgService.begin(FINISHED) def stop(self): logging.info("Stop downloader") if self.video.downloader: self.video.downloader.stop() logging.info("Stop player") self.player.stop() def getPosition(self): return int(self.player.position / 1000000) def isAlive(self): return self.player.isalive() def toggle_pause(self): self.player.toggle_pause() def volup(self): self.player.volup() def voldown(self): self.player.voldown()
from pyomxplayer import OMXPlayer from pprint import pprint import time omx = OMXPlayer('/home/pi/Videos/at.mp4') pprint(omx.__dict__) time.sleep(5) print('toggling pause') omx.toggle_pause() time.sleep(5) print('toggling pause') omx.toggle_pause() time.sleep(5) print('stopping') omx.stop()
import os from pyomxplayer import OMXPlayer loop1 = OMXPlayer('/home/pi/videos/background.mp4', '-o local', start_playback=True) loop2 = OMXPlayer('/home/pi/videos/Nature.mp4', '-o local', start_playback=True) loop2.toggle_pause() position = loop1.position / 1000000 if position > 12.8: loop1.toggle_pause() sleep(2) os.system( 'pkill -9 -f "/usr/bin/omxplayer.bin -s /home/pi/videos/background.mp4 -o local"' ) os.system( 'pkill -9 -f "/bin/bash /usr/bin/omxplayer -s /home/pi/videos/background.mp4 -o local"' ) sleep(2) loop1 = OMXPlayer('/home/pi/videos/background.mp4', '-o local', start_playback=True) loop1.toggle_pause()
import os from pyomxplayer import OMXPlayer loop1= OMXPlayer('/home/pi/videos/background.mp4', '-o local', start_playback=True) loop2 = OMXPlayer('/home/pi/videos/Nature.mp4', '-o local', start_playback=True) loop2.toggle_pause() position = loop1.position/1000000 if position > 12.8: loop1.toggle_pause() sleep(2) os.system('pkill -9 -f "/usr/bin/omxplayer.bin -s /home/pi/videos/background.mp4 -o local"') os.system('pkill -9 -f "/bin/bash /usr/bin/omxplayer -s /home/pi/videos/background.mp4 -o local"') sleep(2) loop1= OMXPlayer('/home/pi/videos/background.mp4', '-o local', start_playback=True) loop1.toggle_pause()
def test_opening_mp4_file(self): player = OMXPlayer('./tests/test.mp4') player.toggle_pause() time.sleep(1) player.stop() self.assertTrue("Did not complete playing example without errors")
class AirPlay: playing = False seekable = False action_play = False action_play_pause = False add_to_playlist_and_play = "" action_stop = False action_seek_time = 0 omxArgs = "" def __init__(self): args = len(sys.argv) if args > 1: if sys.argv[1] == "jack": self.omxArgs = "" print "Audio output over 3,5mm jack" else: self.omxArgs = "-o hdmi" print "Audio output over HDMI" self.videoAirPlay = None self.videoAirPlay = self self.omx = None self.videoAirPlay.service = VideoAirPlayPlayer( videoAirPlay=self.videoAirPlay, name="VideoAirPi on %s" % (platform.node()), host=self.get_ip_address("eth0"), port=8000, ) def signal_handler(self, signal, frame): print "\nQuiting - please wait...." self.Stop() self.videoAirPlay.service.exit() sys.exit(0) def get_ip_address(self, ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack("256s", ifname[:15]))[20:24]) # SIOCGIFADDR def PlayMedia(self, fullpath, startPosition): # , tag, unknown1, unknown2, unknown3): global parsed_path global media_key global duration # print startPosition # print 'Args' # print self.omxArgs # not supported in HLS video stream # if (startPosition != 0): # self.omxArgs += " -f " + str(startPosition) # print self.omxArgs if self.omx: self.Stop() print fullpath self.omx = OMXPlayer(fullpath, args=self.omxArgs, start_playback=True) def Pause(self, message): if self.omx: self.omx.set_speed(1) self.omx.toggle_pause() def Play(self, message): if self.omx: ret = self.omx.set_speed(1) if ret == 0: self.omx.toggle_pause() def Stop(self, message=""): if self.omx: self.omx.stop() self.omx = None def do_activate(self): pass def do_deactivate(self): self.videoAirPlay.service.__del__() def is_playing(self): return self.playing def get_property(self, propertyType): return 100 def action_stop(self): pass def action_play(self): pass def is_seekable(self): return self.seekable
class xbmcCommands: def __init__(self, omxArgs): self.media = None self.plex = PlexInterface() self.omx = None self.omxArgs = omxArgs def PlayMedia(self, fullpath, tag, unknown1, unknown2, unknown3): global parsed_path global media_key global duration parsed_path = urlparse(fullpath) media_path = parsed_path.scheme + "://" + parsed_path.netloc + tag self.media = self.plex.getMedia(media_path) #print 'mediapath', mediapath if(self.omx): self.Stop() transcodeURL = self.media.getTranscodeURL() print transcodeURL self.omx = OMXPlayer(transcodeURL, args=self.omxArgs, start_playback=True) def Pause(self, message): if(self.omx): self.omx.set_speed(1) self.omx.toggle_pause() def Play(self, message): if(self.omx): ret = self.omx.set_speed(1) if(ret == 0): self.omx.toggle_pause() def Stop(self, message=""): if(self.omx): self.omx.stop() self.omx = None def stopPyplex(self, message): self.Stop() global service pygame.quit() exit() def SkipNext(self, message = None): if(self.omx): self.omx.increase_speed() def SkipPrevious(self, message = None): if(self.omx): self.omx.decrease_speed() def StepForward(self, message = None): if(self.omx): self.omx.increase_speed() def StepBack(self, message = None): if(self.omx): self.omx.decrease_speed() def BigStepForward(self, message = None): if(self.omx): self.omx.jump_fwd_600() def BigStepBack(self, message = None): if(self.omx): self.omx.jump_rev_600() def getMilliseconds(self,s): hours, minutes, seconds = (["0", "0"] + ("%s" % s).split(":"))[-3:] hours = int(hours) minutes = int(minutes) seconds = float(seconds) miliseconds = int(3600000 * hours + 60000 * minutes + 1000 * seconds) return miliseconds def getPosMilli(self): return self.getMilliseconds(self.omx.position) def setPlayed(self): self.media.setPlayed() def isFinished(self): if(self.omx): finished = self.omx.finished else: finished = True return finished def isRunning(self): if(self.omx): return True return False def updatePosition(self): if self.isFinished(): if (self.getPosMilli() > (self.media.duration * .95)): self.setPlayed() self.Stop() else: self.media.updatePosition(self.getPosMilli())
# and an LED to make sure the button is working properly yLed = LED(20) yButton.when_pressed = yLed.on yButton.when_released = yLed.off # we'll use another button for quitting the program (since it runs fullscreen) rButton = Button(19, pull_up=False, bounce_time=0.05) # sets up the video player omx = OMXPlayer('../movs/MechanicalPrinciples.mov') try: # run this next section forever, until user stops the programme by pressing button while True: # play video if button is pressed and video player is currently paused if yButton.is_pressed and omx.paused: omx.toggle_pause() # pause video if button is not pressed and player is not paused if (not yButton.is_pressed) and (not omx.paused): omx.toggle_pause() # when quit button is pressed, stop player and quit programme if rButton.is_pressed: omx.stop() sys.exit(0) # this is some magic code that detects when user hits ctrl-c (and stops the programme) except KeyboardInterrupt, SystemExit: omx.stop() sys.exit(0)
self.integer = num def make_playlist(path): temp = os.listdir(path) for name in temp: name2 = name.replace(" ", "") os.system("mv " + name + ".mp3 " + name2 + ".mp3 -i") temp2 = os.listdir(path) shuffle(temp2) return temp2 try: GPIO.add_event_detect(playpausePin, GPIO.RISING) player = OMXPlayer('/home/pi/Desktop/Music/' + temp2[i]) player.toggle_pause() about_to_toggle_pause = False x = dumb(0) def play_pause(pin_num): y = x if y.integer == 0: y.integer = 1 player.toggle_pause() def skip(pin_num): i = i + 1 player = OMXPlayer('/home/pi/Desktop/Music/' + temp2[i]) GPIO.add_event_callback(playpausePin, play_pause) while True: