Skip to content

Commit

Permalink
release v1.0.13 (#201)
Browse files Browse the repository at this point in the history
new in v1.0.13

* Additional date/time functionality added. Allows you to add a second smaller line to display things like the date correctly.
* pressing spacebar will pause/resume omxplayer and image_player

---------

Co-authored-by: DanBaigo <[email protected]>
Co-authored-by: Tobias Perschon <[email protected]>
Co-authored-by: Redacted99 <[email protected]>
  • Loading branch information
4 people authored Nov 16, 2023
1 parent 5aad09b commit 5e55532
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Adafruit_Video_Looper/hello_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def play(self, movie, loop=None, **kwargs):
self._process = subprocess.Popen(args,
stdout=open(os.devnull, 'wb'),
close_fds=True)
def pause(self):
#todo add pause to HelloVideoPlayer
print("pausing is not supported in HelloVideoPlayer")

def is_playing(self):
"""Return true if the video player is running, false otherwise."""
Expand Down
8 changes: 6 additions & 2 deletions Adafruit_Video_Looper/image_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, config, screen, bgimage):
self._loop = 0
self._startTime = 0
self._bgimage = bgimage
self._isPaused = False

def _load_config(self, config):
self._extensions = config.get('image_player', 'extensions') \
Expand Down Expand Up @@ -78,9 +79,12 @@ def play(self, image, loop=None, **kwargs):

self._startTime = monotonic()

def pause(self):
self._isPaused = not self._isPaused

def is_playing(self):
"""Here we need to compare for how long the image was displayed, also taking the in and set playing to false if time is up also"""
if self._loop <= -1: #loop one image = play forever
"""Here we need to compare for how long the image was displayed"""
if self._loop <= -1 or self._isPaused: #loop one image = play forever
return True

playing = (monotonic() - self._startTime) < self._duration*self._loop
Expand Down
7 changes: 7 additions & 0 deletions Adafruit_Video_Looper/omxplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ def play(self, movie, loop=None, vol=0):
args.extend(['--subtitles', srt_path])
args.append(movie.filename) # Add movie file path.
# Run omxplayer process and direct standard output to /dev/null.
# Establish input pipe for commands
self._process = subprocess.Popen(args,
stdout=open(os.devnull, 'wb'),
stdin=subprocess.PIPE,
close_fds=True)

def pause(self):
if self.is_playing():
self._process.stdin.write('p'.encode())
self._process.stdin.flush()

def is_playing(self):
"""Return true if the video player is running, false otherwise."""
if self._process is None:
Expand Down
53 changes: 48 additions & 5 deletions Adafruit_Video_Looper/video_looper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from .alsa_config import parse_hw_device
from .model import Playlist, Movie
from .playlist_builders import build_playlist_m3u
from datetime import datetime

# Basic video looper architecure:
#
Expand Down Expand Up @@ -65,7 +64,8 @@ def __init__(self, config_path):
self._wait_time = self._config.getint('video_looper', 'wait_time')
# Get timedisplay settings
self._datetime_display = self._config.getboolean('video_looper', 'datetime_display')
self._datetime_display_format = self._config.get('video_looper', 'datetime_display_format', raw=True)
self._top_datetime_display_format = self._config.get('video_looper', 'top_datetime_display_format', raw=True)
self._bottom_datetime_display_format = self._config.get('video_looper', 'bottom_datetime_display_format', raw=True)
# Parse string of 3 comma separated values like "255, 255, 255" into
# list of ints for colors.
self._bgcolor = list(map(int, self._config.get('video_looper', 'bgcolor')
Expand Down Expand Up @@ -99,6 +99,7 @@ def __init__(self, config_path):
# Set other static internal state.
self._extensions = '|'.join(self._player.supported_extensions())
self._small_font = pygame.font.Font(None, 50)
self._medium_font = pygame.font.Font(None, 96)
self._big_font = pygame.font.Font(None, 250)
self._running = True
self._playbackStopped = False
Expand Down Expand Up @@ -299,14 +300,52 @@ def _animate_countdown(self, playlist):
time.sleep(1)

def _display_datetime(self):
# returns suffix based on the day
def get_day_suffix(day):
if day in [1, 21, 31]:
suffix = "st"
elif day in [2, 22]:
suffix = "nd"
elif day in [3, 23]:
suffix = "rd"
else:
suffix = "th"
return suffix

sw, sh = self._screen.get_size()

for i in range(self._wait_time):
now = datetime.now()
timeLabel = self._render_text(now.strftime(self._datetime_display_format), self._big_font)
lw, lh = timeLabel.get_size()

# Get the day suffix
suffix = get_day_suffix(int(now.strftime('%d')))

# Format the time and date strings
top_format = self._top_datetime_display_format.replace('%d{SUFFIX}', f'%d{suffix}')
bottom_format = self._bottom_datetime_display_format.replace('%d{SUFFIX}', f'%d{suffix}')

top_str = now.strftime(top_format)
bottom_str = now.strftime(bottom_format)

# Render the time and date labels
top_label = self._render_text(top_str, self._big_font)
bottom_label = self._render_text(bottom_str, self._medium_font)

# Calculate the label positions
l1w, l1h = top_label.get_size()
l2w, l2h = bottom_label.get_size()

top_x = sw // 2 - l1w // 2
top_y = sh // 2 - (l1h + l2h) // 2
bottom_x = sw // 2 - l2w // 2
bottom_y = top_y + l1h + 50

# Draw the labels to the screen
self._screen.fill(self._bgcolor)
self._screen.blit(timeLabel, (round(sw/2-lw/2), round(sh/2-lh/2)))
self._screen.blit(top_label, (top_x, top_y))
self._screen.blit(bottom_label, (bottom_x, bottom_y))
pygame.display.update()

time.sleep(1)

def _idle_message(self):
Expand Down Expand Up @@ -389,6 +428,10 @@ def _handle_keyboard_shortcuts(self):
self._print("s was pressed. stopping...")
self._playbackStopped = True
self._player.stop(3)
# space is pause/resume the playing video
if event.key == pygame.K_SPACE:
self._print("Pause/Resume pressed")
self._player.pause()
if event.key == pygame.K_p:
self._print("p was pressed. shutting down...")
self.quit(True)
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ For a detailed tutorial visit: <https://learn.adafruit.com/raspberry-pi-video-lo
There are also pre-compiled images available from <https://videolooper.de> (but they might not always contain the latest version of pi_video_looper)

## Changelog
#### new in v1.0.13
- Additional date/time functionality added.
Allows you to add a second smaller line to display things like the date correctly.
- pressing spacebar will pause/resume omxplayer and image_player

#### new in v1.0.12
- date/time display option
allows you to display the current date and time between the videos
Expand Down Expand Up @@ -141,9 +146,10 @@ The following keyboard commands are active by default (can be disabled in the [v
* "b" - Back - stops the playback of current file and plays previous file
* "s" - Stop/Start - stops or starts playback of current file
* "p" - Power off - stop playback and shutdown RPi
* " " - (space bar) - Pause/Resume the omxplayer and imageplayer

#### troubleshooting:
* nothing happening (screen flashes once) when in copymode and new drive is plugged in?
* check if you have the "password file" on your drive (see copymode explained above)
* log output can be found in `/var/log/supervisor/`. Enable detailed logging in the video_looper.ini with console_output = true.
Use `sudo tail -f /var/log/supervisor/video_looper-stdout*` and `sudo tail -f /var/log/supervisor/video_looper-stderr*` to view the logs.
Use `sudo tail -f /var/log/supervisor/video_looper-stdout*` and `sudo tail -f /var/log/supervisor/video_looper-stderr*` to view the logs.
21 changes: 18 additions & 3 deletions assets/video_looper.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,23 @@ wait_time = 0
datetime_display= false
#datetime_display = true

# this controls the format the date/time is displayed: (see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes)
datetime_display_format = %H:%M:%S
# This controls the format the date/time is displayed: (see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes)
# The below datetime_display can be on two lines if required. The top line is much bigger than the bottom line and suits the time better. The bottom line is more suited to the date. 'Thursday 13th February 2023' for example.
# If the bottom line not required just leave bottom_datetime_display_format empty.
# If the suffix is required after the day then %d{SUFFIX} should be put in the *_datetime_display_format.
# Some different examples of time and date are shown below with an example. (Only one pair of *_datetime_display_format should be without #)

# 24Hour:Minutes:Seconds on the top line, Day of week, day of month followed by the suffix (st, nd, rd etc), Month, Year ion the bottom line.
top_datetime_display_format = %H:%M:%S
bottom_datetime_display_format = %A %d{SUFFIX} %B %Y

# 24Hour:Minutes:Seconds on the top line, Year on the bottom line.
#top_datetime_display_format = %H:%M:%S
#bottom_datetime_display_format = %Y

# 24Hour:Minutes:Seconds on the top line, no bottom line.
#top_datetime_display_format = %H:%M:%S
#bottom_datetime_display_format =

# To play files in random order set this to true
is_random = false
Expand Down Expand Up @@ -250,4 +265,4 @@ scale = true

# Controls if images should be displayed centered. Default: true
center = true
#center = false
#center = false
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(name = 'Adafruit_Video_Looper',
version = '1.0.12',
version = '1.0.13',
author = 'Tony DiCola',
author_email = '[email protected]',
description = 'Application to turn your Raspberry Pi into a dedicated looping video playback device, good for art installations, information displays, or just playing cat videos all day.',
Expand Down

0 comments on commit 5e55532

Please sign in to comment.