mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-07 00:40:02 +01:00
tidy up video player logic so that switch button is stronger and loop should stop when error state is reached
This commit is contained in:
@@ -79,7 +79,7 @@ class Actions(object):
|
||||
self.load_this_slot_into_next_player(9)
|
||||
|
||||
def trigger_next_player(self):
|
||||
self.video_driver.manual_next = True
|
||||
self.video_driver.switch_players_and_play_video()
|
||||
|
||||
def cycle_display_mode(self):
|
||||
self.display.top_menu_index = 0
|
||||
|
||||
@@ -1 +1 @@
|
||||
[{"start": 607.690078, "end": 610.079466, "length": 1132.04, "name": "mushroom-dreams.mp4", "location": "/media/pi/TIM/videos_to_play/mushroom-dreams.mp4"}, {"start": -1, "end": -1, "length": 3.008, "name": "samplerloop3s3.mp4", "location": "/media/pi/TIM/samplerloop3s3.mp4"}, {"start": -1, "end": -1, "length": 804.245, "name": "long_spinning.mp4", "location": "/media/pi/TIM/videos_to_play/long_spinning.mp4"}, {"start": 66.892487, "end": 68.500718, "length": 87.04, "name": "colour_pixel_02.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_02.mp4"}, {"end": -1, "start": -1, "length": 52.757, "name": "colour_pixel_03.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_03.mp4"}, {"end": -1, "start": -1, "length": 52.757, "name": "colour_pixel_03.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_03.mp4"}, {"end": -1, "start": -1, "length": 52.757, "name": "colour_pixel_03.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_03.mp4"}, {"end": -1, "start": -1, "length": 52.757, "name": "colour_pixel_03.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_03.mp4"}, {"end": -1, "start": -1, "length": 52.757, "name": "colour_pixel_03.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_03.mp4"}, {"end": -1, "start": -1, "length": 52.757, "name": "colour_pixel_03.mp4", "location": "/media/pi/TIM/videos_to_play/colour_pixel_03.mp4"}]
|
||||
[{"location": "/media/pi/TIM1/videos_to_play/colour_pixel_01.mp4", "length": 49.28, "start": -1, "name": "colour_pixel_01.mp4", "end": -1}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}, {"length": -1, "start": -1, "name": "", "end": -1, "location": ""}]
|
||||
@@ -37,7 +37,7 @@
|
||||
"DEFAULT": ["load_slot_1_into_next_player"]
|
||||
},
|
||||
"l": {
|
||||
"DEFAULT": ["load_slot_2_into_next_player"]
|
||||
"DEFAULT": ["load_slot_2_into_next_player","clear_all_slots"]
|
||||
},
|
||||
"m": {
|
||||
"DEFAULT": ["load_slot_3_into_next_player"]
|
||||
|
||||
@@ -1 +1 @@
|
||||
4
|
||||
0
|
||||
@@ -1 +1 @@
|
||||
[{"name": "SCREEN_SIZE", "options": ["dev_mode", "XGA", "composite"]}, {"name": "quit_the_program", "options": ["run_action"]}, {"name": "switch_display_to_hdmi", "options": ["run_action"]}, {"name": "switch_display_to_lcd", "options": ["run_action"]}]
|
||||
[{"options": ["dev_mode", "XGA", "composite"], "name": "SCREEN_SIZE"}, {"options": ["run_action"], "name": "quit_the_program"}, {"options": ["run_action"], "name": "switch_display_to_hdmi"}, {"options": ["run_action"], "name": "switch_display_to_lcd"}]
|
||||
@@ -8,12 +8,14 @@ class VideoDriver(object):
|
||||
self.data = data
|
||||
self.delay = 50
|
||||
self.has_omx = self.data.has_omx
|
||||
self.in_first_load_cycle = False
|
||||
self.in_current_playing_cycle = False
|
||||
self.in_next_load_cycle = False
|
||||
print(self.has_omx)
|
||||
if self.has_omx:
|
||||
self.last_player = video_player(self.root, self.message_handler, self.data, 'a.a')
|
||||
self.current_player = video_player(self.root,self.message_handler, self.data, 'b.b')
|
||||
self.next_player = video_player(self.root, self.message_handler, self.data, 'c.c')
|
||||
self.manual_next = False
|
||||
self.print_status()
|
||||
self.root.after(self.delay, self.begin_playing)
|
||||
else:
|
||||
@@ -28,16 +30,27 @@ class VideoDriver(object):
|
||||
|
||||
def begin_playing(self):
|
||||
# TODO: the first clip will be a demo
|
||||
self.current_player.load()
|
||||
if self.current_player.try_load():
|
||||
self.in_first_load_cycle = True
|
||||
self.wait_for_first_load()
|
||||
else:
|
||||
print('load failed')
|
||||
|
||||
def wait_for_first_load(self):
|
||||
|
||||
if self.in_first_load_cycle:
|
||||
if self.current_player.is_loaded():
|
||||
self.in_first_load_cycle = False
|
||||
self.play_video()
|
||||
else:
|
||||
self.root.after(self.delay, self.wait_for_first_load)
|
||||
|
||||
def switch_players_and_play_video(self):
|
||||
self.in_first_load_cycle = False
|
||||
self.in_current_playing_cycle = False
|
||||
self.in_next_load_cycle = True
|
||||
|
||||
self.switch_if_next_is_loaded()
|
||||
|
||||
def switch_players(self):
|
||||
temp_player = self.last_player
|
||||
self.last_player = self.current_player
|
||||
@@ -47,22 +60,30 @@ class VideoDriver(object):
|
||||
|
||||
def play_video(self):
|
||||
self.current_player.play()
|
||||
self.next_player.load()
|
||||
self.next_player.try_load()
|
||||
self.in_current_playing_cycle = True
|
||||
self.wait_for_next_cycle()
|
||||
|
||||
def wait_for_next_cycle(self):
|
||||
if self.current_player.is_finished() or self.manual_next:
|
||||
self.manual_next = False
|
||||
self.wait_for_next_load()
|
||||
if self.in_current_playing_cycle:
|
||||
if self.current_player.is_finished():
|
||||
self.in_current_playing_cycle = False
|
||||
self.in_next_load_cycle = True
|
||||
self.switch_if_next_is_loaded()
|
||||
else:
|
||||
self.root.after(self.delay, self.wait_for_next_cycle)
|
||||
|
||||
def wait_for_next_load(self):
|
||||
def switch_if_next_is_loaded(self):
|
||||
if self.in_next_load_cycle:
|
||||
if self.next_player.is_loaded():
|
||||
self.in_next_load_cycle = False
|
||||
self.switch_players()
|
||||
self.play_video()
|
||||
else:
|
||||
self.root.after(self.delay, self.wait_for_next_load)
|
||||
if self.next_player.status != 'ERROR':
|
||||
self.root.after(self.delay, self.switch_if_next_is_loaded)
|
||||
else:
|
||||
self.in_next_load_cycle = False
|
||||
|
||||
def get_info_for_player_display(self):
|
||||
if self.has_omx:
|
||||
|
||||
@@ -19,6 +19,21 @@ class video_player:
|
||||
self.end = -1.0
|
||||
self.crop_length = 0.0
|
||||
self.location = ''
|
||||
self.load_attempts = 0
|
||||
|
||||
def try_load(self):
|
||||
load_attempts = 0
|
||||
while(load_attempts < 4):
|
||||
load_attempts = load_attempts + 1
|
||||
if self.load():
|
||||
print('load success')
|
||||
return True
|
||||
else:
|
||||
print('load failed')
|
||||
self.message_handler.set_message('ERROR', 'failed to load')
|
||||
self.status = 'ERROR'
|
||||
return False
|
||||
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
@@ -38,9 +53,11 @@ class video_player:
|
||||
if self.start > 0.5:
|
||||
self.set_position(self.start - 0.5)
|
||||
self.pause_at_start()
|
||||
self.load_attempts = 0
|
||||
return True
|
||||
except:
|
||||
self.message_handler.set_message('ERROR', 'first load error')
|
||||
self.root.after(100, self.load)
|
||||
self.message_handler.set_message('ERROR', 'load attempt fail')
|
||||
return False
|
||||
|
||||
def pause_at_start(self):
|
||||
position = self.get_position()
|
||||
|
||||
Reference in New Issue
Block a user