public class MainActivity extends Activity{
MediaPlayer mediaPlayer1,mediaPlayer2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mediaPlayer1 = MediaPlayer.create(this,R.raw.shoot.mp3);
AssetManager asset = getAssets();
try{
AssetFileDescriptor asf = asset.openFd("shot.mp3");
mediaPlayer2 = new MediaPlayer();
mediaPlayer2.setDataSource(asf.getFileDescriptor());
mediaPlayer2.prepare();
}catch (Exception e){
e.printStackTrace();
}
findViewById(R.id.btnRaw).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mediaPlayer1.start();
}
});
findViewById(R.id.btnPlay).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mediaPlayer2.start();
}
});
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android的原始资源Raw和Assert资源的使用-android学习之旅(五十七)
原文地址:http://blog.csdn.net/lpjishu/article/details/46714945