Fix streaming part1

This commit is contained in:
Tim Bentley 2019-06-14 18:54:04 +01:00
parent 2b4842b20d
commit 7143fbb8d1
4 changed files with 54 additions and 9 deletions

View File

@ -210,6 +210,8 @@ class Settings(QtCore.QSettings):
'media/media auto start': QtCore.Qt.Unchecked, 'media/media auto start': QtCore.Qt.Unchecked,
'media/stream command': '', 'media/stream command': '',
'media/vlc arguments': '', 'media/vlc arguments': '',
'media/video': '',
'media/audio': '',
'remotes/download version': '0.0', 'remotes/download version': '0.0',
'players/background color': '#000000', 'players/background color': '#000000',
'servicemanager/last directory': None, 'servicemanager/last directory': None,

View File

@ -184,7 +184,8 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
display.has_audio = False display.has_audio = False
self.vlc_player.setup(display, preview) self.vlc_player.setup(display, preview)
def set_controls_visible(self, controller, value): @staticmethod
def set_controls_visible(controller, value):
""" """
After a new display is configured, all media related widget will be created too After a new display is configured, all media related widget will be created too
@ -276,6 +277,8 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
# display.frame.runJavaScript('show_video("setBackBoard", null, null,"visible");') # display.frame.runJavaScript('show_video("setBackBoard", null, null,"visible");')
# now start playing - Preview is autoplay! # now start playing - Preview is autoplay!
autoplay = False autoplay = False
if service_item.is_capable(ItemCapabilities.CanStream):
autoplay = True
# Preview requested # Preview requested
if not controller.is_live: if not controller.is_live:
autoplay = True autoplay = True

View File

@ -88,9 +88,6 @@ class MediaTab(SettingsTab):
self.left_layout.addWidget(self.vlc_arguments_group_box) self.left_layout.addWidget(self.vlc_arguments_group_box)
self.left_layout.addStretch() self.left_layout.addStretch()
self.right_layout.addStretch() self.right_layout.addStretch()
self.video_edit.editingFinished.connect(self.on_field_changed)
self.audio_edit.editingFinished.connect(self.on_field_changed)
# # Signals and slots
def retranslate_ui(self): def retranslate_ui(self):
""" """
@ -107,10 +104,13 @@ class MediaTab(SettingsTab):
""" """
self.auto_start_check_box.setChecked(Settings().value(self.settings_section + '/media auto start')) self.auto_start_check_box.setChecked(Settings().value(self.settings_section + '/media auto start'))
self.stream_cmd.setText(Settings().value(self.settings_section + '/stream command')) self.stream_cmd.setText(Settings().value(self.settings_section + '/stream command'))
self.audio_edit.setText(Settings().value(self.settings_section + '/audio'))
self.video_edit.setText(Settings().value(self.settings_section + '/video'))
if not self.stream_cmd.text(): if not self.stream_cmd.text():
self.set_base_stream() self.set_base_stream()
self.vlc_arguments_edit.setPlainText(Settings().value(self.settings_section + '/vlc arguments')) self.vlc_arguments_edit.setPlainText(Settings().value(self.settings_section + '/vlc arguments'))
if Settings().value('advanced/experimental'): if Settings().value('advanced/experimental'):
# vlc.MediaPlayer().audio_output_device_enum()
for cam in QCameraInfo.availableCameras(): for cam in QCameraInfo.availableCameras():
log.debug(cam.deviceName()) log.debug(cam.deviceName())
log.debug(cam.description()) log.debug(cam.description())
@ -134,9 +134,8 @@ class MediaTab(SettingsTab):
Settings().setValue(setting_key, self.auto_start_check_box.checkState()) Settings().setValue(setting_key, self.auto_start_check_box.checkState())
Settings().setValue(self.settings_section + '/stream command', self.stream_cmd.text()) Settings().setValue(self.settings_section + '/stream command', self.stream_cmd.text())
Settings().setValue(self.settings_section + '/vlc arguments', self.vlc_arguments_edit.toPlainText()) Settings().setValue(self.settings_section + '/vlc arguments', self.vlc_arguments_edit.toPlainText())
Settings().setValue(self.settings_section + '/video', self.video_edit.text())
def on_field_changed(self): Settings().setValue(self.settings_section + '/audio', self.audio_edit.text())
self.set_base_stream()
self.stream_cmd.setText(self.stream_cmd.text().format(video=self.video_edit.text(), self.stream_cmd.setText(self.stream_cmd.text().format(video=self.video_edit.text(),
audio=self.audio_edit.text())) audio=self.audio_edit.text()))

View File

@ -27,6 +27,7 @@ from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.core.ui.media.mediacontroller import MediaController from openlp.core.ui.media.mediacontroller import MediaController
from openlp.core.ui.media import ItemMediaInfo
from tests.helpers.testmixin import TestMixin from tests.helpers.testmixin import TestMixin
from tests.utils.constants import RESOURCE_PATH from tests.utils.constants import RESOURCE_PATH
@ -57,7 +58,7 @@ class TestMediaController(TestCase, TestMixin):
# THEN: The player's resize method should be called correctly # THEN: The player's resize method should be called correctly
mocked_player.resize.assert_called_with(mocked_display) mocked_player.resize.assert_called_with(mocked_display)
def test_check_file_type(self): def test_check_file_type_null(self):
""" """
Test that we don't try to play media when no players available Test that we don't try to play media when no players available
""" """
@ -71,7 +72,47 @@ class TestMediaController(TestCase, TestMixin):
ret = media_controller._check_file_type(mocked_controller, mocked_display) ret = media_controller._check_file_type(mocked_controller, mocked_display)
# THEN: it should return False # THEN: it should return False
assert ret is False, '_check_file_type should return False when no mediaplayers are available.' assert ret is False, '_check_file_type should return False when no media file matches.'
def test_check_file_video(self):
"""
Test that we process a file that is valid
"""
# GIVEN: A mocked UiStrings, get_used_players, controller, display and service_item
media_controller = MediaController()
mocked_controller = MagicMock()
mocked_display = MagicMock()
media_controller.media_players = MagicMock()
mocked_controller.media_info = ItemMediaInfo()
mocked_controller.media_info.file_info = [TEST_PATH / 'mp3_file.mp3']
media_controller.current_media_players = {}
media_controller.vlc_player = MagicMock()
# WHEN: calling _check_file_type when no players exists
ret = media_controller._check_file_type(mocked_controller, mocked_display)
# THEN: it should return False
assert ret is True, '_check_file_type should return True when audio file is present and matches.'
def test_check_file_audio(self):
"""
Test that we process a file that is valid
"""
# GIVEN: A mocked UiStrings, get_used_players, controller, display and service_item
media_controller = MediaController()
mocked_controller = MagicMock()
mocked_display = MagicMock()
media_controller.media_players = MagicMock()
mocked_controller.media_info = ItemMediaInfo()
mocked_controller.media_info.file_info = [TEST_PATH / 'mp4_file.mp4']
media_controller.current_media_players = {}
media_controller.vlc_player = MagicMock()
# WHEN: calling _check_file_type when no players exists
ret = media_controller._check_file_type(mocked_controller, mocked_display)
# THEN: it should return False
assert ret is True, '_check_file_type should return True when media file is present and matches.'
def test_media_play_msg(self): def test_media_play_msg(self):
""" """