Skip to content
Browse files

[airplay/airtunes] - backup volume on airplay/airtunes volume change …

…and restore it on playback stop
  • Loading branch information...
1 parent 7f0b5c6 commit 4ba8264bb54c999e7bf4fd8aa95fd8c42a81561e @Memphiz Memphiz committed Mar 13, 2013
View
20 xbmc/network/AirPlayServer.cpp
@@ -153,6 +153,7 @@ void CAirPlayServer::Announce(AnnouncementFlag flag, const char *sender, const c
{
if (strcmp(message, "OnStop") == 0)
{
+ restoreVolume();
ServerInstance->AnnounceToClients(EVENT_STOPPED);
}
else if (strcmp(message, "OnPlay") == 0)
@@ -255,6 +256,7 @@ CAirPlayServer::CAirPlayServer(int port, bool nonlocal) : CThread("AirPlayServer
m_nonlocal = nonlocal;
m_ServerSocket = INVALID_SOCKET;
m_usePassword = false;
+ m_origVolume = -1;
CAnnouncementManager::AddAnnouncer(this);
}
@@ -680,6 +682,23 @@ bool CAirPlayServer::CTCPClient::checkAuthorization(const CStdString& authStr,
return m_bAuthenticated;
}
+void CAirPlayServer::backupVolume()
+{
+ if (ServerInstance->m_origVolume == -1)
+ ServerInstance->m_origVolume = g_application.GetVolume();
+}
+
+void CAirPlayServer::restoreVolume()
+{
+ if (ServerInstance->m_origVolume != -1)
+ {
+ float oldVolume = g_application.GetVolume();
+ g_application.SetVolume((float)ServerInstance->m_origVolume);
+ CApplicationMessenger::Get().ShowVolumeBar(oldVolume < (float)ServerInstance->m_origVolume);
+ ServerInstance->m_origVolume = -1;
+ }
+}
+
int CAirPlayServer::CTCPClient::ProcessRequest( CStdString& responseHeader,
CStdString& responseBody)
{
@@ -767,6 +786,7 @@ int CAirPlayServer::CTCPClient::ProcessRequest( CStdString& responseHeader,
volume *= 100;
if(oldVolume != (int)volume)
{
+ backupVolume();
g_application.SetVolume(volume);
CApplicationMessenger::Get().ShowVolumeBar(oldVolume < volume);
}
View
3 xbmc/network/AirPlayServer.h
@@ -48,6 +48,8 @@ class CAirPlayServer : public CThread, public ANNOUNCEMENT::IAnnouncer
static void StopServer(bool bWait);
static bool SetCredentials(bool usePassword, const CStdString& password);
static bool IsPlaying(){ return m_isPlaying > 0;}
+ static void backupVolume();
+ static void restoreVolume();
static int m_isPlaying;
protected:
@@ -107,6 +109,7 @@ class CAirPlayServer : public CThread, public ANNOUNCEMENT::IAnnouncer
bool m_nonlocal;
bool m_usePassword;
CStdString m_password;
+ int m_origVolume;
static CAirPlayServer *ServerInstance;
};
View
17 xbmc/network/AirTunesServer.cpp
@@ -46,11 +46,13 @@
#include "settings/AdvancedSettings.h"
#include "utils/EndianSwap.h"
#include "URL.h"
+#include "interfaces/AnnouncementManager.h"
#include <map>
#include <string>
using namespace XFILE;
+using namespace ANNOUNCEMENT;
#if defined(TARGET_WINDOWS)
DllLibShairplay *CAirTunesServer::m_pLibShairplay = NULL;
@@ -93,6 +95,16 @@ void CAirTunesServer::SetMetadataFromBuffer(const char *buffer, unsigned int siz
CApplicationMessenger::Get().SetCurrentSongTag(tag);
}
+void CAirTunesServer::Announce(AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data)
+{
+ if ( (flag & Player) && strcmp(sender, "xbmc") == 0 && strcmp(message, "OnStop") == 0)
+ {
+#ifdef HAS_AIRPLAY
+ CAirPlayServer::restoreVolume();
+#endif
+ }
+}
+
void CAirTunesServer::SetCoverArtFromBuffer(const char *buffer, unsigned int size)
{
XFILE::CFile tmpFile;
@@ -192,6 +204,9 @@ void CAirTunesServer::AudioOutputFunctions::audio_set_volume(void *cls, void *s
{
//volume from -30 - 0 - -144 means mute
float volPercent = volume < -30.0f ? 0 : 1 - volume/-30;
+#ifdef HAS_AIRPLAY
+ CAirPlayServer::backupVolume();
+#endif
g_application.SetVolume(volPercent, false);//non-percent volume 0.0-1.0
}
@@ -563,6 +578,7 @@ CAirTunesServer::CAirTunesServer(int port, bool nonlocal) : CThread("AirTunesSer
#else
m_pLibShairport = new DllLibShairport();
#endif
+ CAnnouncementManager::AddAnnouncer(this);
}
CAirTunesServer::~CAirTunesServer()
@@ -581,6 +597,7 @@ CAirTunesServer::~CAirTunesServer()
}
delete m_pLibShairport;
#endif
+ CAnnouncementManager::RemoveAnnouncer(this);
}
void CAirTunesServer::Process()
View
5 xbmc/network/AirTunesServer.h
@@ -41,13 +41,16 @@
#include "utils/HttpParser.h"
#include "utils/StdString.h"
#include "filesystem/PipeFile.h"
+#include "interfaces/IAnnouncer.h"
class DllLibShairport;
-class CAirTunesServer : public CThread
+class CAirTunesServer : public CThread, public ANNOUNCEMENT::IAnnouncer
{
public:
+ virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
+
static bool StartServer(int port, bool nonlocal, bool usePassword, const CStdString &password="");
static void StopServer(bool bWait);
static void SetMetadataFromBuffer(const char *buffer, unsigned int size);

0 comments on commit 4ba8264

Please sign in to comment.
Something went wrong with that request. Please try again.