diff options
author | Chris Browet <koying@semperpax.com> | 2013-10-20 08:04:43 -0700 |
---|---|---|
committer | Chris Browet <koying@semperpax.com> | 2013-10-20 08:04:43 -0700 |
commit | 7ca44c80c6afb7965cde407accf6b7e234f4aa3d (patch) | |
tree | ece62c82b6c854ddf18f0d3b7a2e1d8d852cc24d | |
parent | d6fea6a847eea1adbe659790fb71c91c1544c1ae (diff) | |
parent | dd6321d3cdc95a23a97480bb6cfbd5c5b17bb754 (diff) |
Merge pull request #3025 from koying/fixdroidrestorevolume
FIX: [droid] restore system volume on exit
-rw-r--r-- | xbmc/android/activity/XBMCApp.cpp | 28 | ||||
-rw-r--r-- | xbmc/android/activity/XBMCApp.h | 3 | ||||
-rw-r--r-- | xbmc/android/jni/AudioManager.cpp | 9 | ||||
-rw-r--r-- | xbmc/android/jni/AudioManager.h | 1 |
4 files changed, 40 insertions, 1 deletions
diff --git a/xbmc/android/activity/XBMCApp.cpp b/xbmc/android/activity/XBMCApp.cpp index 1dc2a547c2..036601a0cc 100644 --- a/xbmc/android/activity/XBMCApp.cpp +++ b/xbmc/android/activity/XBMCApp.cpp @@ -85,6 +85,7 @@ CEvent CXBMCApp::m_windowCreated; ANativeActivity *CXBMCApp::m_activity = NULL; ANativeWindow* CXBMCApp::m_window = NULL; int CXBMCApp::m_batteryLevel = 0; +int CXBMCApp::m_initialVolume = 0; CXBMCApp::CXBMCApp(ANativeActivity* nativeActivity) : CJNIContext(nativeActivity) @@ -132,6 +133,10 @@ void CXBMCApp::onResume() void CXBMCApp::onPause() { android_printf("%s: ", __PRETTY_FUNCTION__); + + // Restore volume + SetSystemVolume(m_initialVolume); + unregisterReceiver(*this); } @@ -246,6 +251,8 @@ void CXBMCApp::run() int status = 0; SetupEnv(); + + m_initialVolume = GetSystemVolume(); CJNIIntent startIntent = getIntent(); android_printf("XBMC Started with action: %s\n",startIntent.getAction().c_str()); @@ -513,6 +520,27 @@ int CXBMCApp::GetMaxSystemVolume(JNIEnv *env) return 0; } +int CXBMCApp::GetSystemVolume() +{ + CJNIAudioManager audioManager(getSystemService("audio")); + if (audioManager) + return audioManager.getStreamVolume(); + else + { + android_printf("CXBMCApp::GetSystemVolume: Could not get Audio Manager"); + return 0; + } +} + +void CXBMCApp::SetSystemVolume(int val) +{ + CJNIAudioManager audioManager(getSystemService("audio")); + if (audioManager) + audioManager.setStreamVolume(val); + else + android_printf("CXBMCApp::SetSystemVolume: Could not get Audio Manager"); +} + void CXBMCApp::SetSystemVolume(JNIEnv *env, float percent) { CJNIAudioManager audioManager(getSystemService("audio")); diff --git a/xbmc/android/activity/XBMCApp.h b/xbmc/android/activity/XBMCApp.h index 8259c23912..cd7d10169a 100644 --- a/xbmc/android/activity/XBMCApp.h +++ b/xbmc/android/activity/XBMCApp.h @@ -99,6 +99,8 @@ public: static bool GetExternalStorage(std::string &path, const std::string &type = ""); static bool GetStorageUsage(const std::string &path, std::string &usage); static int GetMaxSystemVolume(); + static int GetSystemVolume(); + static void SetSystemVolume(int val); static int GetDPI(); protected: @@ -118,6 +120,7 @@ private: static ANativeActivity *m_activity; CJNIWakeLock *m_wakeLock; static int m_batteryLevel; + static int m_initialVolume; bool m_firstrun; bool m_exiting; pthread_t m_thread; diff --git a/xbmc/android/jni/AudioManager.cpp b/xbmc/android/jni/AudioManager.cpp index 3ddf0badbf..5983852dea 100644 --- a/xbmc/android/jni/AudioManager.cpp +++ b/xbmc/android/jni/AudioManager.cpp @@ -23,7 +23,7 @@ using namespace jni; -int CJNIAudioManager::STREAM_MUSIC(0); +int CJNIAudioManager::STREAM_MUSIC(3); void CJNIAudioManager::PopulateStaticFields() { @@ -38,6 +38,13 @@ int CJNIAudioManager::getStreamMaxVolume() STREAM_MUSIC); } +int CJNIAudioManager::getStreamVolume() +{ + return call_method<int>(m_object, + "getStreamVolume", "(I)I", + STREAM_MUSIC); +} + void CJNIAudioManager::setStreamVolume(int index /* 0 */, int flags /* NONE */) { call_method<void>(m_object, diff --git a/xbmc/android/jni/AudioManager.h b/xbmc/android/jni/AudioManager.h index 22ad9e8d9f..85256f8b6b 100644 --- a/xbmc/android/jni/AudioManager.h +++ b/xbmc/android/jni/AudioManager.h @@ -29,6 +29,7 @@ public: // Note removal of streamType param. int getStreamMaxVolume(); + int getStreamVolume(); void setStreamVolume(int index = 0, int flags = 0); static void PopulateStaticFields(); |