0
我正在做一個音板應用程序,這是我必須解決的最後一件事,感謝您的幫助! 我想讓聲音停止,然後我點擊一個新的。當開始播放新媒體時,MediaPlayer OnClicListener停止播放
package com.passaros;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.murdersquirrel.newboard.R;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.Toast;
public class newBoard extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Toast.makeText(this, "Long touch to save as Ringtones.", Toast.LENGTH_LONG).show();
AdView layout = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adRequest.setTesting(true);
layout.loadAd(adRequest);
final MediaPlayer sound01 = MediaPlayer.create(this, R.raw.sound01);
final MediaPlayer sound02 = MediaPlayer.create(this, R.raw.sound02);
//more and more....
Button s01 = (Button) findViewById(R.id.button01);
s01.setText(this.getString(R.string.quote01));
s01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
sound01.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sound01.start();
}
});
registerForContextMenu(s01);
再次感謝!
忽略這一點:我只是打字東西,因爲該網站認爲,我沒有使用足夠的話,以幫助該代碼....
Nop,沒有工作......沒有任何變化,我試圖把sound01.stop /暫停在一些地方,但沒有任何 – rzfzr