0
在位於7 ImageView的XML文件,例如:播放聲音
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:scaleType="centerInside"
android:src="@drawable/imageview1"
android:clickable="true"
android:layout_gravity="center"
/>
在類:PageFragment延伸片段我創建陣列
MediaPlayer[] mediaPlayers= new MediaPlayer[7];
初始化元件
mediaPlayers[0] = MediaPlayer.create(getActivity(), R.raw.england);
mediaPlayers[1]= MediaPlayer.create(getActivity(), R.raw.german);
mediaPlayers[2]= MediaPlayer.create(getActivity(), R.raw.ukraina);
mediaPlayers[3]= MediaPlayer.create(getActivity(), R.raw.russian);
mediaPlayers[4]= MediaPlayer.create(getActivity(), R.raw.belarus);
mediaPlayers[5]= MediaPlayer.create(getActivity(), R.raw.litva);
mediaPlayers[6]= MediaPlayer.create(getActivity(), R.raw.japan);
我想播放聲音後點擊圖片查看
switch (v.getId()) {
case R.id.imageView1:
play mediaPlayers[0]
,我想:如果我在imagevie2點擊正在播放的mediaPlayers [1]音
你試過'mediaPlayers [0] .play();'? –
是的,但是如果我點擊mediaPlayers [1] .play(); 聲音播放,但mediaPlayers [0] .play();繼續播放聲音 – upward