Android listview中的媒体播放器
我在ListView中重现声音。我有一个自定义适配器,但它总是失败的行,我把int与mp3的资源!不知道我肯定会做些什么,但不知道是什么!如何解决问题的建议?多谢各位Android listview中的媒体播放器,android,listview,media-player,Android,Listview,Media Player,我在ListView中重现声音。我有一个自定义适配器,但它总是失败的行,我把int与mp3的资源!不知道我肯定会做些什么,但不知道是什么!如何解决问题的建议?多谢各位 public class Adapter_animal extends ArrayAdapter<String> { private final Activity context; private final String[] animal; private final int[] animal_id; privat
public class Adapter_animal extends ArrayAdapter<String> {
private final Activity context;
private final String[] animal;
private final int[] animal_id;
private MediaPlayer mp;
public Adapter_animal(Activity context, int mylist, String[] animal, int[] animal_id) {
super(context, R.layout.mylist, animal);
// TODO Auto-generated constructor stub
this.context=context;
this.animal = animal;
this.animal_id = animal_id;
}
public View getView(final int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.mylist, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titolo);
txtTitle.setText(animal[position]);
FloatingActionButton btn = (FloatingActionButton) rowView.findViewById(R.id.f1_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopPlaying();
mp = MediaPlayer.create(Adapter_animal.this, animal_id); //error in this line "cannot resolve method
mp.start();
}
});
return rowView;
};
private void stopPlaying() {
if (mp != null) {
mp.stop();
mp.release();
mp = null;
}
}
您正在将数组传递给需要单个资源id的方法
publicstaticmediaplayer创建(上下文,intresid)
为给定资源id创建MediaPlayer
的便捷方法。成功后,prepare()
将已被调用,不得再次调用
使用MediaPlayer
后,应调用release()
,以释放资源。如果不发布,过多的MediaPlayer
实例将导致异常
请注意,由于此方法自动调用了prepare()
,因此无法更改新MediaPlayer
的音频流类型(请参见setAudioStreamType(int)
)、音频会话ID(请参见setAudioSessionId(int)
)或音频属性(请参见setAudioAttributes(AudioAttributes)
)
参数
上下文
-要使用的上下文
resid
-要用作数据源的资源的原始资源id(R.raw.
)
返回
MediaPlayer
-一个MediaPlayer
对象,如果创建失败,则为空
我会更改什么?抱歉,我不是专家,我想知道如何修复!使用数组中的索引器传递所需的资源id。即:animal_id[0]
static String[] animal={
"animale",
"animale2",
"animale3",
};
static int[] animal_id={
R.raw.a11_ovation,
};