diff --git a/es-app/src/VolumeControl.cpp b/es-app/src/VolumeControl.cpp index 989d8e323..334987664 100644 --- a/es-app/src/VolumeControl.cpp +++ b/es-app/src/VolumeControl.cpp @@ -1,4 +1,5 @@ #include "VolumeControl.h" +#include "Settings.h" #include "Log.h" @@ -73,6 +74,10 @@ void VolumeControl::init() //try to open mixer device if (mixerHandle == nullptr) { + #ifdef _RPI_ + mixerName = Settings::getInstance()->getString("AudioDevice").c_str(); + #endif + snd_mixer_selem_id_alloca(&mixerSelemId); //sets simple-mixer index and name snd_mixer_selem_id_set_index(mixerSelemId, mixerIndex); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 0d826ccb1..9735b0f60 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -69,6 +69,23 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN [this] { auto s = new GuiSettings(mWindow, "SOUND SETTINGS"); + #ifdef _RPI_ + // volume control device + auto vol_dev = std::make_shared< OptionListComponent >(mWindow, "AUDIO DEVICE", false); + std::vector transitions; + transitions.push_back("PCM"); + transitions.push_back("Speaker"); + transitions.push_back("Master"); + for(auto it = transitions.begin(); it != transitions.end(); it++) + vol_dev->add(*it, *it, Settings::getInstance()->getString("AudioDevice") == *it); + s->addWithLabel("AUDIO DEVICE", vol_dev); + s->addSaveFunc([vol_dev] { + Settings::getInstance()->setString("AudioDevice", vol_dev->getSelected()); + VolumeControl::getInstance()->deinit(); + VolumeControl::getInstance()->init(); + }); + #endif + // volume auto volume = std::make_shared(mWindow, 0.f, 100.f, 1.f, "%"); volume->setValue((float)VolumeControl::getInstance()->getVolume()); @@ -204,6 +221,23 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN if(needReload) ViewController::get()->reloadAll(); }); + + // OMX player Audio Device + auto omx_audio_dev = std::make_shared< OptionListComponent >(mWindow, "OMX PLAYER AUDIO DEVICE", false); + std::vector devices; + devices.push_back("local"); + devices.push_back("hdmi"); + devices.push_back("both"); + // USB audio + devices.push_back("alsa:hw:0,0"); + devices.push_back("alsa:hw:1,0"); + for (auto it = devices.begin(); it != devices.end(); it++) + omx_audio_dev->add(*it, *it, Settings::getInstance()->getString("OMXAudioDev") == *it); + s->addWithLabel("OMX PLAYER AUDIO DEVICE", omx_audio_dev); + s->addSaveFunc([omx_audio_dev] { + if (Settings::getInstance()->getString("OMXAudioDev") != omx_audio_dev->getSelected()) + Settings::getInstance()->setString("OMXAudioDev", omx_audio_dev->getSelected()); + }); #endif auto video_audio = std::make_shared(mWindow); video_audio->setState(Settings::getInstance()->getBool("VideoAudio")); diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index aa816fb6c..ac74ad68e 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -81,6 +81,15 @@ void Settings::setDefaults() // we don't get a warning if we encounter it on a different platform mBoolMap["VideoOmxPlayer"] = false; mBoolMap["VideoAudio"] = true; + // Audio out device for Video playback using OMX player. + mStringMap["OMXAudioDev"] = "both"; + + // Audio out device for volume control + #ifdef _RPI_ + mStringMap["AudioDevice"] = "PCM"; + #else + mStringMap["AudioDevice"] = "Master"; + #endif } diff --git a/es-core/src/components/VideoPlayerComponent.cpp b/es-core/src/components/VideoPlayerComponent.cpp index cc4645e1d..3096688fa 100644 --- a/es-core/src/components/VideoPlayerComponent.cpp +++ b/es-core/src/components/VideoPlayerComponent.cpp @@ -1,5 +1,6 @@ #ifdef _RPI_ #include "components/VideoPlayerComponent.h" +#include "AudioManager.h" #include "Renderer.h" #include "ThemeData.h" #include "Settings.h" @@ -57,6 +58,9 @@ void VideoPlayerComponent::startVideo() // Set the video that we are going to be playing so we don't attempt to restart it mPlayingVideoPath = mVideoPath; + // Disable AudioManager so video can play + AudioManager::getInstance()->deinit(); + // Start the player process pid_t pid = fork(); if (pid == -1) @@ -84,7 +88,7 @@ void VideoPlayerComponent::startVideo() // We need to specify the layer of 10000 or above to ensure the video is displayed on top // of our SDL display - const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "--win", buf, "-b", "", "", "", "", NULL }; + const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf, "-b", "", "", "", "", NULL }; // check if we want to mute the audio if (!Settings::getInstance()->getBool("VideoAudio")) @@ -98,7 +102,9 @@ void VideoPlayerComponent::startVideo() argv[6] = "stretch"; } - argv[11] = mPlayingVideoPath.c_str(); + argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str(); + + argv[13] = mPlayingVideoPath.c_str(); const char* env[] = { "LD_LIBRARY_PATH=/opt/vc/libs:/usr/lib/omxplayer", NULL }; @@ -134,6 +140,8 @@ void VideoPlayerComponent::stopVideo() int status; kill(mPlayerPid, SIGKILL); waitpid(mPlayerPid, &status, WNOHANG); + // Restart AudioManager + AudioManager::getInstance()->init(); mPlayerPid = -1; } }