Skip to content

Commit

Permalink
add: display date/time feature (adafruit#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
tofuSCHNITZEL authored Sep 13, 2022
1 parent 388f08a commit 5aad09b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
25 changes: 21 additions & 4 deletions Adafruit_Video_Looper/video_looper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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 @@ -56,13 +56,16 @@ def __init__(self, config_path):
# Load other configuration values.
self._osd = self._config.getboolean('video_looper', 'osd')
self._is_random = self._config.getboolean('video_looper', 'is_random')
self._resume_playlist = self._config.getboolean('video_looper', 'resume_playlist')
self._resume_playlist = self._config.getboolean('video_looper', 'resume_playlist')
self._keyboard_control = self._config.getboolean('video_looper', 'keyboard_control')
self._copyloader = self._config.getboolean('copymode', 'copyloader')
# Get seconds for countdown from config
self._countdown_time = self._config.getint('video_looper', 'countdown_time')
# Get seconds for waittime bewteen files from config
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)
# 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 @@ -295,6 +298,17 @@ def _animate_countdown(self, playlist):
# Pause for a second between each frame.
time.sleep(1)

def _display_datetime(self):
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()
self._screen.fill(self._bgcolor)
self._screen.blit(timeLabel, (round(sw/2-lw/2), round(sh/2-lh/2)))
pygame.display.update()
time.sleep(1)

def _idle_message(self):
"""Print idle message from file reader."""
# Print message to console.
Expand Down Expand Up @@ -409,8 +423,11 @@ def run(self):
movie.was_played()

if self._wait_time > 0 and not self._firstStart:
self._print('Waiting for: {0} seconds'.format(self._wait_time))
time.sleep(self._wait_time)
if(self._datetime_display):
self._display_datetime()
else:
self._print('Waiting for: {0} seconds'.format(self._wait_time))
time.sleep(self._wait_time)
self._firstStart = False

#generating infotext
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ There are also pre-compiled images available from <https://videolooper.de> (but

## Changelog
#### new in v1.0.12
- date/time display option
allows you to display the current date and time between the videos
- added "back" keyboard shortcut to play previous file

#### v1.0.11
Expand Down Expand Up @@ -130,6 +132,8 @@ Note: files with the same name always get overwritten.

* if you have only one video then omxplayer will also loop seamlessly (and with audio)

* to reduce the wear of the SD card and potentially extend the lifespan of the player, you could enable the overlay filesystem via `raspi-config` and select Performance Options->Overlay Filesystem

#### keyboard commands:
The following keyboard commands are active by default (can be disabled in the [video_looper.ini](https://github.com/adafruit/pi_video_looper/blob/master/assets/video_looper.ini)):
* "ESC" - stops playback and exits video_looper
Expand Down
8 changes: 8 additions & 0 deletions assets/video_looper.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ countdown_time = 5
# with omxplayer wait_time will also happen between every repeat of a video
wait_time = 0

# This option enables the display of the current date/time while waiting between the videos
# Please note that the RPi is not good at keeping the time so you need to setup NTP time sync or install a RTC module
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

# To play files in random order set this to true
is_random = false
#is_random = true
Expand Down
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.11',
version = '1.0.12',
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 5aad09b

Please sign in to comment.