experimental work with dif sampler playmodes

This commit is contained in:
langolierz
2018-04-26 07:44:17 +00:00
parent bd88a24aac
commit 5af091b9e2
6 changed files with 72 additions and 33 deletions

View File

@@ -93,6 +93,9 @@ class Actions(object):
def toggle_pause_on_player(self):
self.video_driver.current_player.toggle_pause()
def toggle_show_on_player(self):
self.video_driver.current_player.toggle_show()
def seek_forward_on_player(self):
self.video_driver.current_player.seek(30)
@@ -177,6 +180,9 @@ class Actions(object):
output_range = max_param - min_param
return int(( cc_value / 127 ) * output_range + min_param)
def update_video_settings(self, setting_value):
self.video_driver.update_video_settings()
def change_output_mode(self, setting_value):
if setting_value == 'hdmi':
subprocess.call(['tvservice', '-p'])

View File

@@ -18,9 +18,9 @@
},
{
"end": -1,
"length": -1,
"location": "",
"name": "",
"length": 4.714,
"location": "/media/pi/5EB5-664C/recur test videos/samplerloop3s2.mp4",
"name": "samplerloop3s2.mp4",
"rate": 1,
"start": -1
},

View File

@@ -11,7 +11,7 @@
},
"c": {
"NAV_BROWSER": ["enter_on_browser_selection"],
"PLAYER": ["toggle_pause_on_player"],
"PLAYER": ["toggle_pause_on_player","toggle_show_on_player"],
"NAV_SETTINGS": ["enter_on_settings_selection"]
},
"d": {

View File

@@ -80,7 +80,7 @@
},
"sampler": {
"ACTION_GATED": {
"action": null,
"action": "update_video_settings",
"options": [
"on",
"off"
@@ -93,7 +93,7 @@
"value": ""
},
"FIXED_LENGTH_MODE": {
"action": "cycle_setting_options",
"action": "update_video_settings",
"options": [
"on",
"off"
@@ -101,7 +101,7 @@
"value": "off"
},
"LOAD_NEXT": {
"action": null,
"action": "update_video_settings",
"options": [
"now",
"random",
@@ -110,7 +110,7 @@
"value": "now"
},
"ON_ACTION": {
"action": null,
"action": "update_video_settings",
"options": [
"pause/hide",
"pause/show",
@@ -120,35 +120,33 @@
"value": "pause/hide"
},
"ON_FINISH": {
"action": null,
"action": "update_video_settings",
"options": [
"nothing",
"switch"
],
"value": "pause/hide"
"value": "switch"
},
"ON_LOAD": {
"action": null,
"action": "update_video_settings",
"options": [
"pause/hide",
"pause/show",
"play/hide",
"play/show"
"hide",
"show"
],
"value": "pause/hide"
"value": "show"
},
"ON_START": {
"action": null,
"action": "update_video_settings",
"options": [
"pause/hide",
"pause/show",
"play/hide",
"play/show"
],
"value": "pause/hide"
"value": "play/show"
},
"RAND_START_MODE": {
"action": "cycle_setting_options",
"action": "update_video_settings",
"options": [
"on",
"off"

View File

@@ -15,13 +15,26 @@ class VideoDriver(object):
self.next_player = VideoPlayer(self.root, self.message_handler, self.data, 'c.c')
self.root.after(self.delay, self.begin_playing)
self.switch_on_finish = self.data.settings['sampler']['ON_FINISH']['value'] == 'switch'
self.play_on_start = 'play' in self.data.settings['sampler']['ON_START']['value']
self.show_on_start = 'show' in self.data.settings['sampler']['ON_START']['value']
self.play_on_load = 'play' in self.data.settings['sampler']['ON_LOAD']['value']
self.show_on_load = 'show' in self.data.settings['sampler']['ON_LOAD']['value']
def update_video_settings(self):
self.switch_on_finish = self.data.settings['sampler']['ON_FINISH']['value'] == 'switch'
self.play_on_start = 'play' in self.data.settings['sampler']['ON_START']['value']
self.show_on_start = 'show' in self.data.settings['sampler']['ON_START']['value']
self.show_on_load = 'show' == self.data.settings['sampler']['ON_LOAD']['value']
def print_status(self):
print('l({}):{}, c({}):{}, n({}):{}'.format(self.last_player.name, self.last_player.status, self.current_player.name, self.current_player.status, self.next_player.name, self.next_player.status,))
self.root.after(1000,self.print_status)
def begin_playing(self):
# TODO: the first clip will be a demo
if self.current_player.try_load():
if self.current_player.try_load(self.show_on_load):
self.in_first_load_cycle = True
self.wait_for_first_load()
else:
@@ -50,9 +63,11 @@ class VideoDriver(object):
#self.last_player.exit()
def play_video(self):
self.current_player.play()
print(self.play_on_start)
if self.play_on_start:
self.current_player.play(self.show_on_start)
self.last_player.exit()
self.next_player.try_load()
self.next_player.try_load(self.show_on_load)
self.in_current_playing_cycle = True
self.wait_for_next_cycle()
@@ -61,6 +76,7 @@ class VideoDriver(object):
if self.current_player.is_finished():
self.in_current_playing_cycle = False
self.in_next_load_cycle = True
if self.switch_on_finish:
self.switch_if_next_is_loaded()
else:
self.root.after(self.delay, self.wait_for_next_cycle)
@@ -86,3 +102,6 @@ class VideoDriver(object):
self.next_player.exit()
self.current_player.exit()
def reload_next_player(self):
self.next_player.reload(self,show_on_load)

View File

@@ -18,11 +18,13 @@ class VideoPlayer:
self.location = ''
self.load_attempts = 0
def try_load(self):
self.show_toggle_on = True
def try_load(self, show):
load_attempts = 0
while(load_attempts < 2):
load_attempts = load_attempts + 1
if self.load():
if self.load(show):
print('load success')
return True
else:
@@ -32,7 +34,7 @@ class VideoPlayer:
return False
def load(self):
def load(self, show):
try:
self.get_context_for_player()
is_dev_mode, first_screen_arg, second_screen_arg = self.set_screen_size_for_dev_mode()
@@ -52,7 +54,7 @@ class VideoPlayer:
print('{}: the duration is {}'.format(self.name, self.total_length))
if self.start > 0.9:
self.set_position(self.start - 0.9)
self.pause_at_start()
self.pause_at_start(show)
#print('set rate to {}'.format(self.rate))
#self.omx_player.set_rate(self.rate)
#self.load_attempts = 0
@@ -61,20 +63,26 @@ class VideoPlayer:
#self.message_handler.set_message('ERROR', 'load attempt fail')
return False
def pause_at_start(self):
def pause_at_start(self, show):
position = self.get_position()
start_threshold = round(self.start - 0.05,2)
#print('is playing: {} , position : {} , start_threshold : {}'.format(self.omx_player.is_playing(), position, start_threshold))
if position > start_threshold:
self.status = 'LOADED'
self.omx_player.set_alpha(255)
#if show:
# self.omx_player.set_alpha(255)
#else:
# self.omx_player.set_alpha(0)
self.omx_player.pause()
elif self.omx_running:
self.root.after(5, self.pause_at_start)
self.root.after(5, self.pause_at_start, show)
def play(self):
def play(self, show):
self.status = 'PLAYING'
#self.omx_player.set_alpha(255)
if show:
self.omx_player.set_alpha(255)
else:
self.omx_player.set_alpha(0)
self.omx_player.play()
self.pause_at_end()
@@ -91,7 +99,7 @@ class VideoPlayer:
def reload(self):
self.exit()
self.omx_running = False
self.try_load()
self.try_load(True)
def is_loaded(self):
return self.status is 'LOADED'
@@ -119,6 +127,14 @@ class VideoPlayer:
self.omx_player.play_pause()
self.status = self.omx_player.playback_status().upper()
def toggle_show(self):
if self.show_toggle_on:
self.show_toggle_on = False
self.omx_player.set_alpha(0)
else:
self.show_toggle_on = True
self.omx_player.set_alpha(255)
def seek(self, amount):
position = self.get_position()
after_seek_position = position + amount