Update RandomMusicPlayer sample for new RemoteControlClient APIs, also add media button support
Change-Id: Ia6ad08dd0ec1e67f1cffa2d6cfca2120ee0a96c7
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
@@ -71,7 +72,6 @@ public class MainActivity extends Activity implements OnClickListener {
|
||||
mEjectButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View target) {
|
||||
// Send the correct intent to the MusicService, according to the button that was clicked
|
||||
if (target == mPlayButton)
|
||||
@@ -119,4 +119,15 @@ public class MainActivity extends Activity implements OnClickListener {
|
||||
|
||||
alertBuilder.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||
startService(new Intent(MusicService.ACTION_TOGGLE_PLAYBACK));
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user