using different layers for each video so now and next can be mixed

This commit is contained in:
langolierz
2018-04-30 22:42:28 +00:00
parent 6e0d0b963d
commit 31eaa36199
5 changed files with 41 additions and 47 deletions

View File

@@ -42,7 +42,7 @@ class Actions(object):
def _load_this_slot_into_next_player(self, slot):
self.data.update_next_slot_number(slot)
self.video_driver.next_player.reload()
self.video_driver.reload_next_player()
def load_slot_0_into_next_player(self):
self._load_this_slot_into_next_player(0)

View File

@@ -95,25 +95,11 @@ class Data(object):
self.next_bankslot = '{}-{}'.format(self.bank_number,new_value)
self._update_json(self.NEXT_BANKSLOT_JSON,self.next_bankslot)
def check_if_setting_selection_is_action_otherwise_cycle_value(self, setting_index):
######## update the value of selected setting by cycling through valid options ########
if(self.setting['options'][0] == 'run_action'):
return True, self.setting['name']
else:
self.cycle_setting_value(setting_index)
return False, None
def update_setting_value(self, setting_folder, setting_name, setting_value):
self.settings[setting_folder][setting_name]['value'] = setting_value
self._update_json(self.SETTINGS_JSON, self.settings)
return self.settings[setting_folder][setting_name]
def cycle_setting_value(self, setting_index):
this_setting_option = self.settings[setting_index]['options']
this_setting_option= this_setting_option[len(this_setting_option)-1:]+this_setting_option[0:len(this_setting_option)-1]
self.settings[setting_index]['options'] = this_setting_option
self._update_json(self.SETTINGS_JSON, self.settings)
@classmethod
def split_bankslot_number(cls, bankslot_number):
split = bankslot_number.split('-')

View File

@@ -2,25 +2,25 @@
[
{
"end": -1,
"length": 1132.04,
"location": "/media/pi/5EB5-664C/recur test videos/mushroom-dreams.mp4",
"name": "mushroom-dreams.mp4",
"length": 804.245,
"location": "/media/pi/5EB5-664C/recur test videos/long_spinning.mp4",
"name": "long_spinning.mp4",
"rate": 1,
"start": -1
},
{
"end": -1,
"length": 6.96,
"location": "/home/pi/Videos/recordings/rec-2018-04-25-1.mp4",
"name": "rec-2018-04-25-1.mp4",
"length": 40.533,
"location": "/media/pi/5EB5-664C/recur test videos/colour_pixal_04.mp4",
"name": "colour_pixal_04.mp4",
"rate": 1,
"start": -1
},
{
"end": -1,
"length": 4.714,
"location": "/media/pi/5EB5-664C/recur test videos/samplerloop3s2.mp4",
"name": "samplerloop3s2.mp4",
"length": -1,
"location": "",
"name": "",
"rate": 1,
"start": -1
},

View File

@@ -1,6 +1,9 @@
from video_centre.video_player import VideoPlayer
class VideoDriver(object):
MAX_LAYER = 1000000000
def __init__(self, root, message_handler, data):
self.root = root
self.message_handler = message_handler
@@ -10,16 +13,15 @@ class VideoDriver(object):
self.in_current_playing_cycle = False
self.in_next_load_cycle = False
self.layer = self.MAX_LAYER
self.last_player = VideoPlayer(self.root, self.message_handler, self.data, 'a.a')
self.current_player = VideoPlayer(self.root,self.message_handler, self.data, 'b.b')
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']
self.update_video_settings()
def update_video_settings(self):
self.switch_on_finish = self.data.settings['sampler']['ON_FINISH']['value'] == 'switch'
@@ -27,6 +29,12 @@ class VideoDriver(object):
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 get_next_layer_value(self):
if self.layer > 0:
self.layer = self.layer - 1
else:
self.layer = self.MAX_LAYER
return self.layer
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,))
@@ -34,7 +42,7 @@ class VideoDriver(object):
def begin_playing(self):
# TODO: the first clip will be a demo
if self.current_player.try_load(self.show_on_load):
if self.current_player.try_load(self.get_next_layer_value(), self.show_on_load):
self.in_first_load_cycle = True
self.wait_for_first_load()
else:
@@ -67,7 +75,7 @@ class VideoDriver(object):
if self.play_on_start:
self.current_player.play(self.show_on_start)
self.last_player.exit()
self.next_player.try_load(self.show_on_load)
self.next_player.try_load(self.get_next_layer_value() ,self.show_on_load)
self.in_current_playing_cycle = True
self.wait_for_next_cycle()
@@ -103,5 +111,5 @@ class VideoDriver(object):
self.current_player.exit()
def reload_next_player(self):
self.next_player.reload(self,show_on_load)
self.next_player.reload(self.get_next_layer_value(), self.show_on_load)

View File

@@ -20,11 +20,11 @@ class VideoPlayer:
self.show_toggle_on = True
def try_load(self, show):
def try_load(self, layer ,show):
load_attempts = 0
while(load_attempts < 2):
load_attempts = load_attempts + 1
if self.load(show):
if self.load(layer, show):
print('load success')
return True
else:
@@ -34,16 +34,16 @@ class VideoPlayer:
return False
def load(self, show):
def load(self, layer , show):
try:
self.get_context_for_player()
is_dev_mode, first_screen_arg, second_screen_arg = self.set_screen_size_for_dev_mode()
self.arguments = ['--no-osd', '--adev', 'local', '--alpha', '0', first_screen_arg, second_screen_arg]
arguments = ['--no-osd', '--layer', str(layer), '--adev', 'local', '--alpha', '0', first_screen_arg, second_screen_arg]
if not is_dev_mode:
self.arguments.append('-b')
arguments.append('-b')
self.status = 'LOADING'
print('the location is {}'.format(self.location))
self.omx_player = OMXPlayer(self.location, args=self.arguments, dbus_name=self.name)
self.omx_player = OMXPlayer(self.location, args=arguments, dbus_name=self.name)
self.omx_running = True
self.total_length = self.omx_player.duration() # <-- uneeded once self.duration stores float
if(self.end is -1):
@@ -69,11 +69,11 @@ class VideoPlayer:
#print('is playing: {} , position : {} , start_threshold : {}'.format(self.omx_player.is_playing(), position, start_threshold))
if position > start_threshold:
self.status = 'LOADED'
#if show:
# self.omx_player.set_alpha(255)
#else:
# self.omx_player.set_alpha(0)
self.omx_player.pause()
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, show)
@@ -96,10 +96,10 @@ class VideoPlayer:
elif(self.omx_running):
self.root.after(5, self.pause_at_end)
def reload(self):
def reload(self, layer, show):
self.exit()
self.omx_running = False
self.try_load(True)
self.try_load(layer, show)
def is_loaded(self):
return self.status is 'LOADED'