|
楼主 |
发表于 2010-11-17 14:40:43
|
显示全部楼层
dragonksn, david:
Hi, the cause is that the source above is not an android *application*, just a helper class. So it just can’t run by itself.
You have to do something like this:
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final AudioRecorder recorder = new AudioRecorder(“/audiometer/temp”);
recorder.start();
//….wait a while
recorder.stop();
}
}
my stop method calls release, which is why you can’t call stop and then start again. I believe if you take out the call to release you will be able to call start again.
- Sisi said, Hello,
i try this application, but it’s not playing.
I think my path is not good… but i don’t know how i have to change!
Here is my code..it’s a little bit long, because i also use Button. I can’t playing what i have recording!
package com.swyx.AudioRecording2;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Record extends Activity {
//Wahrscheinlich ist den angegebenen Pfad nicht richtig! Nur wie gebe ich richtig ein?
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
//System.out.print(“bis hier geht”);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*Erstelle ein neues Objekt von Typ Button,
das aktiviert wird sobald es geklickt wird*/
Button btn1 = (Button)findViewById(R.id.record);
btn1.setOnClickListener(btnListener1);
Button btn2 = (Button)findViewById(R.id.stop);
btn2.setOnClickListener(btnListener2);
Button btn3 = (Button)findViewById(R.id.play);
btn3.setOnClickListener(btnListener3);
}
//folgendes passiert, wenn auf btn1 geklickt wird
private OnClickListener btnListener1 = new OnClickListener()
{
public void onClick(View v)
{
final AudioRecorder2 recorder = new AudioRecorder2(“C:/Bochum”);
try {
recorder.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//….wait a while
try {
recorder.stop();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
//folgendes passiert, wenn auf btn2 geklickt wird
private OnClickListener btnListener2 = new OnClickListener()
{
public void onClick(View v)
{
MediaPlayer mp = new MediaPlayer();
Toast.makeText(getBaseContext(),
“Hello, please stop!” + mp.isPlaying(),
Toast.LENGTH_LONG).show();
/*
try {
recorder.stop();
} catch (IOException e) {
}*/
}
};
//folgendes passiert, wenn auf btn3 geklickt wird
private OnClickListener btnListener3 = new OnClickListener()
{
public void onClick(View v)
{
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(“C:/Bochum”);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
Toast.makeText(getBaseContext(),
“Hello, please play!” +” is playing?: “+ mp.isPlaying(),
Toast.LENGTH_LONG).show();
}
};
}
Thanks for your help! I’m desesperate!
Sisi
Sisi,
You can’t record to C:\ because that’s a Windows path. Android uses Linux type paths. Try recording to something like “test/tmp.3gp” instead.
|
|