마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

기본 음악 어플 실행 버튼

0 추천
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, 이전곡, 다음곡
>>> 핸드폰에 디버깅 해 보면 
버튼 누르면 아무 반응이 없네요..
어느 부분을 바꿔야 하는지...
보랑이 (160 포인트) 님이 2014년 7월 10일 질문

1개의 답변

0 추천
new Button.OnClickListener()

=> new View.OnClickListener()

로 변경해 보셔요
nicehee (73,100 포인트) 님이 2014년 7월 13일 답변
...