gpt4 book ai didi

android - 随机声音onClick Android Medaplayer

转载 作者:行者123 更新时间:2023-12-02 23:55:30 27 4
gpt4 key购买 nike

我有以下代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);



final MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.ingame_voice_42_);

Button bTutorial1 = (Button) findViewById(R.id.tutorial1);

bTutorial1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mpButtonClick.start();

}
});

}


@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;
}

}

如何更改它,以播放/ raw /文件夹中的随机声音。
是为此更改此代码的简单方法吗?

请帮帮我!

最佳答案

  • 将声音放在 Assets (/ assets / mysounds /)中的单独文件中。
  • 获取声音列表:
    AssetManager assetManager = this.getAssets();
    String[] sounds= assetManager.list("mysounds");
  • 将MediaPlayer设置为随机声音:
    final MediaPlayer mpButtonClick = MediaPlayer.create(this, "mysounds/"+sounds[some_random_int]);
  • 关于android - 随机声音onClick Android Medaplayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16607157/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com