1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import android.media.MediaPlayer;
import android.media.audiofx.Visualizer;
import android.net.Uri;
import android.widget.Spinner;
import android.widget.Button;
import android.content.Context;
public class MainActivity extends Activity {
//Declarations
public String fichierrecord="";
private Button auriculaire=null;
public boolean aTermine=true;
public Spinner selecti;
public byte[] mBytes=null;
public ByteArrayOutputStream buffer;
public Visualizer v;
@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
//"instanciation" du layout...
setContentView(R.layout.relalayou);
selecti=(Spinner) findViewById(R.id.spinner13);
auriculaire=(Button) findViewById(R.id.oreille);
//instanciation du visualizer : je souhaite avoir la sortie son du téléphone quelque soit
// le son émis par le téléphone (ici mediaplayer indirectement ) et ceci sans passer par le //micro
v=new Visualizer(0);
//preparation de la capture
buffer=new ByteArrayOutputStream();
v.setEnabled(false);
v.setCaptureSize(65536);
Visualizer.OnDataCaptureListener c=new Visualizer.OnDataCaptureListener(){
@Override
public void onWaveFormDataCapture(Visualizer vv, byte[] wf, int sr){
mBytes= wf;
if (wf.length>-1){
buffer.write(wf,0,wf.length);}
}
@Override
public void onFftDataCapture(Visualizer vv, byte[] wf, int sr) {
} };
v.setDataCaptureListener(c,Visualizer.getMaxCaptureRate()/2,true,true);
// 'icone' sur lequel on appuie pour débuter et terminer la capture
auriculaire.setOnClickListener(new View.OnClickListener(){//setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override
public void onClick(View arg) {
if (aTermine==true){
Toast.makeText(MainActivity.this, "debute", Toast.LENGTH_LONG).show();
v.setEnabled(true); aTermine=false;}
else {v.setEnabled(false);
try {
buffer.flush();
} catch (IOException e) {
}
mBytes = buffer.toByteArray();
try {
buffer.close();
} catch (IOException e) {
}
v.release();
File f = new File(Environment.getExternalStorageDirectory(), "audiofichier.wav");
FileOutputStream fos;
try {
fos = new FileOutputStream(f);
fos.write(mBytes);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
Toast.makeText(MainActivity.this, "termine", Toast.LENGTH_LONG).show();
}
aTermine=false;
}
// spinner qui permet de selectionner un fichier audio (si "file")
List<String> exem=new ArrayList<String>();
exem.add("pasFile");
exem.add("file");
final ArrayAdapter<String> ada =new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,exem);
selecti.setAdapter(ada);
selecti.setSelection(0);
selectitonalite.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if (selecti.getSelectedItemId()==){
Toast.makeText(MainActivity.this, "Sélectionner le fichier audio (.mp3,.mp4,.m4a,.wav,.3gp,.ogg,.mkv,.mid,.xmf,.mxmf,.rttt1,.rtx,.ota,.imy)" +
"sur lequel vous voulez jouer", Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, "Sélectionner le fichier audio (.mp3,.mp4,.m4a,.wav,.3gp,.ogg,.mkv,.mid,.xmf,.mxmf,.rttt1,.rtx,.ota,.imy)" +
"sur lequel vous voulez jouer", Toast.LENGTH_LONG).show();
File mPath = new File(Environment.getExternalStorageDirectory() + "//DIR//");
FileDialog fileDialog = new FileDialog(MainActivity.this, mPath);
fileDialog.setFileEndsWith(".mp3",".mp4",".m4a",".wav",".3gp",".ogg",".mkv",".mid",".xmf",".mxmf",".rttt1",".rtx",".ota",".imy");//,);
fileDialog.addFileListener(new FileDialog.FileSelectedListener() {
public void fileSelected(File file) {
File mmFichier = new File(fichierrecord);
if (mmFichier.exists()) {
MediaPlayer m= new MediaPlayer();try{m.setDataSource(fichierrecord);m.prepare();}catch(IOException e){};
MediaPlayer.create(getApplicationContext(), Uri.fromFile(mmFichier));
m.setVolume(1f,1f);
m.start();
file.toString());
}}
});
fileDialog.showDialog();
} |
Partager