java如何设置事件侦听器
因此,我设置了一个媒体录制程序,并创建了一个通知方法(notifi),向我发送通知。我的问题是,我希望在媒体录制器停止录制时调用通知方法(mediaRecorder=null)。我想我必须设置某种事件侦听器,但我需要帮助才能做到这一点
public class MainActivity extends AppCompatActivity implements
MediaRecorder.OnInfoListener, MediaController.MediaPlayerControl {
private boolean cont;
private MediaRecorder mediaRecorder;
private MediaPlayer mediaPlayer;
private String OUTPUT_FILE;
private MediaController mediaController;
NotificationCompat.Builder notif;
private static final int uid = 615204;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OUTPUT_FILE = Environment.getExternalStorageDirectory() + "/安卓audio1.3gpp";
cont = true;
notif = new NotificationCompat.Builder(this);
notif.setAutoCancel(true);
}
public void outtfile() {
}
public void clikked(View view) {
switch (view.getId()) {
case R.id.startRec:
beginRecord();
break;
case R.id.stopRec:
stopRecord();
break;
case R.id.startPlay:
try {
begginPlaying();
} catch (IOException e) {
e.printStackTrace();
}
break;
case R.id.stopPlay:
stopPlaying();
break;
}
}
public void notifi(View view) {
notif.setSmallIcon(R.drawable.notifi);
notif.setTicker("Stopped Rec");
notif.setWhen(System.currentTimeMillis());
notif.setContentTitle("App Stopped Rec");
notif.setContentText("App has stopped Rec session");
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notif.setContentIntent(pendingIntent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uid, notif.build());
}
}
# 1 楼答案
我想你需要检查一下