Add a volume setting
This provides a complement to the system media volume, providing more fine-grained control
This commit is contained in:
parent
1b862cc392
commit
87585922f2
@ -26,6 +26,8 @@
|
||||
|
||||
<!-- Preferences -->
|
||||
<string name="pref_output">Audio Output</string>
|
||||
<string name="volume_title">Volume</string>
|
||||
<string name="volume_summary">Music volume</string>
|
||||
<string name="headset_only_title">External Output Only</string>
|
||||
<string name="headset_only_summary">Only play music through an external output (e.g. headphones, Bluetooth)</string>
|
||||
<string name="headset_pause_title">Pause When Unplugged</string>
|
||||
|
@ -3,6 +3,10 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:persistent="true">
|
||||
<PreferenceCategory android:title="@string/pref_output">
|
||||
<org.kreed.vanilla.VolumePreference
|
||||
android:key="volume"
|
||||
android:title="@string/volume_title"
|
||||
android:summary="@string/volume_summary" />
|
||||
<CheckBoxPreference
|
||||
android:key="headset_only"
|
||||
android:title="@string/headset_only_title"
|
||||
|
@ -258,6 +258,9 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
||||
mHeadsetOnly = mSettings.getBoolean("headset_only", false);
|
||||
mNotificationMode = Integer.parseInt(mSettings.getString("notification_mode", "1"));
|
||||
mScrobble = mSettings.getBoolean("scrobble", false);
|
||||
float volume = mSettings.getFloat("volume", 1.0f);
|
||||
if (volume != 1.0f)
|
||||
mMediaPlayer.setVolume(volume, volume);
|
||||
|
||||
PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VanillaMusicSongChangeLock");
|
||||
@ -297,6 +300,11 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
|
||||
updateNotification(getSong(0));
|
||||
} else if ("scrobble".equals(key)) {
|
||||
mScrobble = mSettings.getBoolean("scrobble", false);
|
||||
} else if ("volume".equals(key)) {
|
||||
float volume = mSettings.getFloat("volume", 1.0f);
|
||||
synchronized (mMediaPlayer) {
|
||||
mMediaPlayer.setVolume(volume, volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
75
src/org/kreed/vanilla/VolumePreference.java
Normal file
75
src/org/kreed/vanilla/VolumePreference.java
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
|
||||
*
|
||||
* This file is part of Vanilla Music Player.
|
||||
*
|
||||
* Vanilla Music Player is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Vanilla Music Player is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.kreed.vanilla;
|
||||
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
public class VolumePreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
|
||||
public VolumePreference(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(Builder builder)
|
||||
{
|
||||
// setting is applied instantly; no way to cancel
|
||||
builder.setNegativeButton(null, null);
|
||||
|
||||
ViewGroup.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
LinearLayout layout = new LinearLayout(getContext());
|
||||
layout.setLayoutParams(params);
|
||||
|
||||
SeekBar seekBar = new SeekBar(getContext());
|
||||
seekBar.setPadding(20, 20, 20, 20);
|
||||
seekBar.setLayoutParams(params);
|
||||
seekBar.setMax(1000);
|
||||
seekBar.setProgress((int)(Math.pow(getPersistedFloat(1.0f) / 3, 0.25f) * 1000));
|
||||
seekBar.setOnSeekBarChangeListener(this);
|
||||
layout.addView(seekBar);
|
||||
|
||||
builder.setView(layout);
|
||||
}
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
{
|
||||
// Approximate an exponential curve with x^4. Produces a value from 0.0 - 3.0.
|
||||
if (fromUser && shouldPersist()) {
|
||||
float value = seekBar.getProgress() / 1000.0f;
|
||||
value *= value;
|
||||
value *= value;
|
||||
persistFloat(value * 3);
|
||||
}
|
||||
}
|
||||
|
||||
public void onStartTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user