public class MainActivity extends ActionBarActivity {
protected static final ContextWrapper _context = null;
SeekBar seekbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn_play = (Button)findViewById(R.id.btn_play);
Button btn_rw = (Button)findViewById(R.id.btn_rw);
Button btn_ff = (Button)findViewById(R.id.btn_ff);
Button btn_stop = (Button)findViewById(R.id.btn_stop);
btn_play.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try
{
Intent btn_play = new Intent(Intent.ACTION_MEDIA_BUTTON);
btn_play.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY));
_context.sendOrderedBroadcast(btn_play, null);
btn_play = null;
} catch (Exception e)
{
e.printStackTrace();
}
}
});
btn_rw.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try
{
Intent btn_rw = new Intent(Intent.ACTION_MEDIA_BUTTON);
btn_rw.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
_context.sendOrderedBroadcast(btn_rw, null);
btn_rw = null;
} catch (Exception e)
{
e.printStackTrace();
}
}
});
btn_ff.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try
{
Intent btn_ff = new Intent(Intent.ACTION_MEDIA_BUTTON);
btn_ff.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
_context.sendOrderedBroadcast(btn_ff, null);
btn_ff = null;
} catch (Exception e)
{
e.printStackTrace();
}
}
});
btn_stop.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try
{
Intent btn_stop = new Intent(Intent.ACTION_MEDIA_BUTTON);
btn_stop.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP));
_context.sendOrderedBroadcast(btn_stop, null);
btn_stop = null;
} catch (Exception e)
{
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
/////
play,stop, 이전곡, 다음곡
>>> 핸드폰에 디버깅 해 보면
버튼 누르면 아무 반응이 없네요..
어느 부분을 바꿔야 하는지...