Renderer volume can be changed with volume keys.
This commit is contained in:
parent
167e0c7479
commit
faef0888c2
2 changed files with 59 additions and 0 deletions
|
@ -10,6 +10,7 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
|
@ -145,4 +146,24 @@ public class MainActivity extends SherlockFragmentActivity implements
|
|||
mRendererFragment.setPlaylist(playlist, start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends volume key events to RendererFragment (which sends them to
|
||||
* media renderer).
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
switch (event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
mRendererFragment.changeVolume(true);
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
mRendererFragment.changeVolume(false);
|
||||
return true;
|
||||
default:
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.teleal.cling.support.model.DIDLContent;
|
|||
import org.teleal.cling.support.model.PositionInfo;
|
||||
import org.teleal.cling.support.model.SeekMode;
|
||||
import org.teleal.cling.support.model.item.Item;
|
||||
import org.teleal.cling.support.renderingcontrol.callback.GetVolume;
|
||||
import org.teleal.cling.support.renderingcontrol.callback.SetVolume;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
|
@ -484,4 +486,40 @@ public class RendererFragment extends Fragment implements
|
|||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases or decreases volume.
|
||||
*
|
||||
* @param increase True to increase volume, false to decrease.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void changeVolume(final boolean increase) {
|
||||
if (mCurrentRenderer == null)
|
||||
return;
|
||||
final Service<?, ?> service = mCurrentRenderer.findService(
|
||||
new ServiceType("schemas-upnp-org", "RenderingControl"));
|
||||
mUpnpService.getControlPoint().execute(new GetVolume(service) {
|
||||
|
||||
@Override
|
||||
public void failure(ActionInvocation invocation,
|
||||
UpnpResponse operation, String defaultMessage) {
|
||||
Log.d(TAG, "Failed to get current Volume: " + defaultMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ActionInvocation invocation, int volume) {
|
||||
int newVolume = volume + ((increase) ? 4 : -4);
|
||||
if (newVolume < 0) newVolume = 0;
|
||||
mUpnpService.getControlPoint().execute(new SetVolume(service,
|
||||
newVolume) {
|
||||
|
||||
@Override
|
||||
public void failure(ActionInvocation invocation,
|
||||
UpnpResponse operation, String defaultMessage) {
|
||||
Log.d(TAG, "Failed to set new Volume: " + defaultMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue