我构建了一个带有评论的应用程序,该应用程序从应用程序数据的文件夹中播放一首歌曲..但我希望应用程序从数据设备打开音乐(例如当您连接 samsumg 耳机并按下按钮时)代码:
public MediaPlayer song1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
song1 = MediaPlayer.create(getApplicationContext(), R.raw.smashing_the_opponent);
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.start:
Log.i(tag, "Start item Clicked");
Toast.makeText(getApplicationContext(), "Music On", Toast.LENGTH_LONG).show();
song1.play();
return true;
}
}
如何更改代码?