miklik

filmstop.0.2.2.py

Dec 30th, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # v0.1.0, 15.11.2018, Martin Mikala, initial version
  4. # v0.1.1, 25.11.2018, Martin Mikala, set path to video as path type
  5. # v0.2.0,  9.12.2018, Martin Mikala, change to three buttons version
  6. # v0.2.1, 23.12.2018, Martin Mikala, chnage rewind to slow revert seek
  7. # v0.2.2, 30.12.2018, Martin Mikala, possible push only one button
  8.  
  9. import omxplayer.player
  10. import omxplayer.keys
  11. from pathlib import Path
  12. from gpiozero import Button
  13. import time
  14. from os import system
  15.  
  16. time_jump = 0.1
  17. time_current = time.clock_gettime(0)
  18. time_last = time_current
  19.  
  20. VIDEO_DIR = "/home/pi/"
  21. VIDEO_FILE = "qq1.mp4"
  22. VIDEO_PATH = Path(VIDEO_DIR + VIDEO_FILE)
  23.  
  24. buttonP = Button(26)    # button for pause/start
  25. buttonF = Button(13)    # button forward
  26. buttonR = Button(19)    # button rewind back
  27.  
  28. #time.sleep(5)
  29.  
  30. #while True:
  31. player = omxplayer.player.OMXPlayer(VIDEO_PATH,dbus_name='org.mpris.MediaPlayer2.omxplayer1',args='--loop')
  32.  
  33. while not player.can_control():
  34.     print("Can control %s " % player.can_control())
  35.     sleep(0.1)
  36.  
  37. #print("Start player status %s" % player.playback_status())
  38.  
  39. pushP = False  # status push pause button
  40. lastP = pushP
  41. pushR = False  # status push rewind button
  42. lastR = pushR
  43. pushF = False  # status push forward button
  44. lastF = pushF
  45. pushA = True   # acceppt pusing any button
  46.  
  47. rewind = False
  48. forward = False
  49.  
  50. player.action(omxplayer.keys.SHOW_INFO)
  51.  
  52. while player.can_control():
  53.     time_current = time.clock_gettime(0)
  54.     if time_current - time_last > time_jump:
  55.         #print("last %f curr %f jump %f minus %f" % (time_last,time_current,time_jump,(time_current - time_last)))
  56.         time_last = time_current
  57.         pushP = buttonP.is_pressed
  58.         pushR = buttonR.is_pressed
  59.         pushF = buttonF.is_pressed
  60.        
  61.         if pushP != lastP:             #chanche Play/Pause button
  62.             #print("buttonP")
  63.             #print("player status 1 %s" % player.playback_status())
  64.             if pushP and pushA:                 # button pushed
  65.                 player.pause()      # change mode to pause
  66.                 pushA = False
  67.             else:                       # button released
  68.                 player.play()       # change mode to play
  69.                 pushA = True
  70.                 #print("player status 2 %s" % player.playback_status())
  71.             lastP = pushP               # note button state
  72.    
  73.         if pushF != lastF:              #change FF button
  74.             #print("buttonF")
  75.             #print("player status 1 %s" % player.position())
  76.             if pushF and pushA:                 # button pushed
  77.                 player.set_rate(4)
  78.                 pushA = False
  79.                 #forward = True
  80.             else:
  81.                 player.set_rate(1)
  82.                 pushA = True
  83.                 #forward = False
  84.                 #print("player status 2 %s" % player.position())
  85.             lastF = pushF           #note button state
  86.    
  87.         if pushR != lastR:              #change FF button
  88.             #print("buttonR")
  89.             #print("player status 1 %s" % player.position())
  90.             if pushR and pushA:                   # button pushed
  91.                 rewind = True
  92.                 pushA = False
  93.                 #player.seek(-1)
  94.             else:
  95.                 rewind = False
  96.                 pushA = True
  97.                 #print("player status 2 %s" % player.position())
  98.             lastR = pushR           #note button state
  99.  
  100.         if rewind:
  101.             player.seek(-0.2)
  102.  
  103.         if forward:
  104.             player.seek(0.1)
  105.  
  106.         #print("player position %s , rate %d " % (player.position(), player.rate()))
  107.                    
  108. player.quit()
  109. print("End")
Advertisement
Add Comment
Please, Sign In to add comment