我正在尝试创建一个按钮,允许我通过服务录制音频,我希望按钮有文本:"Start Recording".在OnClick事件上,我希望按钮文本更改为:"Stop Recording".
我有这个代码在类中工作,但现在它不在服务中工作,但是,因为我希望音频记录作为服务工作,我似乎无法更改按钮的文本.我对编码很新,所以任何帮助都将不胜感激!
我的代码如下:
类:
public class Test extends AppCompatActivity {
public void Record(View view) {
Intent intent = new Intent(this, RecordService.class);
startService(intent);
}
public void Play(View view) {
Intent intent = new Intent(this, RecordService.class);
stopService(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
服务:
import android.app.Service;
import android.content.Intent;
import android.media.MediaRecorder;
import android.os.Environment;
import android.os.IBinder;
import android.widget.Button;
import android.view.View;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class RecordService extends Service {
MediaRecorder mRecorder;
public static String audioFilePath;
public boolean …Run Code Online (Sandbox Code Playgroud)