3 つの異なるボタンで構成されるページがあります。一時停止 | 止まる。プレイ | STOP は正常に動作していますが、特定のインスタンスで一時停止できません。一時停止ボタンを押して、インスタンスで再生を一時停止したい。そして、もう一度 [再生] ボタンを押して、保存したインスタンスから再開します。
以下はSound.javaファイルのコードです
public class Sound extends Activity {
MediaPlayer mp = null;
String play = "Play!";
String stop = "Stop!";
String pause = "Pause";
int length;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sound);
final ImageButton play = (ImageButton) findViewById(R.id.idplay);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
managerOfSound("play");
Toast toast_play = Toast.makeText(getBaseContext(),
"Playing First", Toast.LENGTH_SHORT);
toast_play.show();
} // END onClick()
});
final ImageButton pause = (ImageButton) findViewById(R.id.idpause);
pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
managerOfSound("pause");
Toast toast_pause = Toast.makeText(getBaseContext(),
"Pausing Morning Bhajan-Aarati", Toast.LENGTH_SHORT);
toast_pause.show();
} // END onClick()
});
final ImageButton stop = (ImageButton) findViewById(R.id.idstop);
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mp != null) {
mp.stop();
mp.reset();
Toast toast_stop = Toast.makeText(getBaseContext(),
"Stopping First",
Toast.LENGTH_SHORT);
toast_stop.show();
}
} // END onClick()
});
/** Manager of Sounds **/
protected void managerOfSound(String theText) {
if (mp != null){
mp.reset();
mp.release();
}
if (theText == "play")
mp = MediaPlayer.create(this, R.raw.goodbye);
else if (theText == "pause" && mp.isPlaying())
mp.pause();
length = mp.getCurrentPosition();
mp.seekTo(length);
mp.start();
}
これが私のsound.xmlファイルです。
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/idplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="65dp"
android:layout_marginTop="20dp"
android:background="@drawable/image_play" />
<!-- android:text="@string/idplay" /> -->
<ImageButton
android:id="@+id/idpause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_toLeftOf="@+id/idstop"
android:background="@drawable/image_pause" />
<ImageButton
android:id="@+id/idstop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/idplay"
android:background="@drawable/image_stop" />
</RelativeLayout>
あなたの助けに感謝します..!!