Added check to see if given path exists.

This commit is contained in:
Tomas Groth 2014-03-30 21:32:41 +02:00
parent 4b83741b36
commit 73304d7ec3
2 changed files with 12 additions and 8 deletions

View File

@ -122,11 +122,18 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
"""
self.disable_all()
path = self.media_path_combobox.currentText()
# Check if given path is non-empty and exists before starting VLC
if path == '':
log.debug('no given path')
critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm', 'No path was given'))
self.toggle_disable_load_media(False)
return
if not os.path.exists(path):
log.debug('vlc media player is none')
critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
'Given path does not exists'))
self.toggle_disable_load_media(False)
return
self.vlc_media = self.vlc_instance.media_new_path(path)
if not self.vlc_media:
log.debug('vlc media player is none')
@ -141,11 +148,13 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
if self.vlc_media_player.play() < 0:
log.debug('vlc play returned error')
critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
'An error happen when starting VLC player'))
'VLC player failed playing the media'))
self.toggle_disable_load_media(False)
return
self.vlc_media_player.audio_set_mute(True)
if not self.media_state_wait(vlc.State.Playing):
critical_error_message_box(message=translate('MediaPlugin.MediaClipSelectorForm',
'VLC player failed playing the media'))
self.toggle_disable_load_media(False)
return
self.vlc_media_player.pause()
@ -453,4 +462,4 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
continue
dirs = os.listdir('/Volumes/' + volume)
if 'VIDEO_TS' in dirs:
self.media_path_combobox.addItem()
self.media_path_combobox.addItem('/Volumes/' + volume)

View File

@ -56,10 +56,6 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
self.vlc_patcher.start()
# Mock the media item
self.mock_media_item = MagicMock()
# Mock media_state_wait to avoid waiting for VLC playing state
#self.mock_media_state_wait = patch('openlp.plugins.media.forms.mediaclipselectorform.media_state_wait')
#self.mock_media_state_wait.return_value = True
#self.mock_media_state_wait.start()
# create form to test
self.form = MediaClipSelectorForm(self.mock_media_item, self.main_window, None)
mock_media_state_wait = MagicMock()
@ -70,7 +66,6 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
#self.mock_media_state_wait.stop()
self.vlc_patcher.stop()
del self.form
del self.main_window