Merge "[FM] FM recording can not be stopped in notification bar" into lmp-mr1-dev
diff --git a/res/values-zh-rHK/strings.xml b/res/values-zh-rHK/strings.xml
index d8ca937..0782f84 100644
--- a/res/values-zh-rHK/strings.xml
+++ b/res/values-zh-rHK/strings.xml
@@ -48,7 +48,7 @@
<string name="station_title" msgid="4027617747760605320">"電台"</string>
<string name="station_searching_tips" msgid="6970095710072278870">"正在取得電台"</string>
<string name="station_empty_text" msgid="6847327406626186898">"未找到任何電台"</string>
- <string name="minutes_label" msgid="3225846493097986594">"分"</string>
+ <string name="minutes_label" msgid="3225846493097986594">"分鐘"</string>
<string name="seconds_label" msgid="3998011734682420096">"秒"</string>
<string name="timer_default" msgid="8062388403825907344">"00"</string>
<string name="record_title" msgid="8695283158200902780">"正在錄音"</string>
diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml
index 9ce3854..ccdd49e 100644
--- a/res/values-zh-rTW/strings.xml
+++ b/res/values-zh-rTW/strings.xml
@@ -48,7 +48,7 @@
<string name="station_title" msgid="4027617747760605320">"電台"</string>
<string name="station_searching_tips" msgid="6970095710072278870">"正在取得電台清單"</string>
<string name="station_empty_text" msgid="6847327406626186898">"找不到電台"</string>
- <string name="minutes_label" msgid="3225846493097986594">"分"</string>
+ <string name="minutes_label" msgid="3225846493097986594">"分鐘"</string>
<string name="seconds_label" msgid="3998011734682420096">"秒"</string>
<string name="timer_default" msgid="8062388403825907344">"00"</string>
<string name="record_title" msgid="8695283158200902780">"錄音"</string>
diff --git a/src/com/android/fmradio/FmMainActivity.java b/src/com/android/fmradio/FmMainActivity.java
index ec7baf0..b29761f 100644
--- a/src/com/android/fmradio/FmMainActivity.java
+++ b/src/com/android/fmradio/FmMainActivity.java
@@ -322,6 +322,12 @@
boolean isSpeakerMode = bundle.getBoolean(FmListener.KEY_IS_SPEAKER_MODE);
break;
+ case FmListener.LISTEN_RECORDSTATE_CHANGED:
+ if (mService != null) {
+ mService.updatePlayingNotification();
+ }
+ break;
+
default:
break;
}
diff --git a/src/com/android/fmradio/FmRecordActivity.java b/src/com/android/fmradio/FmRecordActivity.java
index b00d146..95ba8e8 100644
--- a/src/com/android/fmradio/FmRecordActivity.java
+++ b/src/com/android/fmradio/FmRecordActivity.java
@@ -442,7 +442,7 @@
if (recordName != null) {
intent.setData(Uri.parse("file://" + FmService.getRecordingSdcard()
+ File.separator + FmRecorder.FM_RECORD_FOLDER + File.separator
- + recordName + FmRecorder.RECORDING_FILE_EXTENSION));
+ + Uri.encode(recordName) + FmRecorder.RECORDING_FILE_EXTENSION));
}
setResult(RESULT_OK, intent);
}
diff --git a/src/com/android/fmradio/FmService.java b/src/com/android/fmradio/FmService.java
index d9ac99e..8681224 100644
--- a/src/com/android/fmradio/FmService.java
+++ b/src/com/android/fmradio/FmService.java
@@ -97,6 +97,9 @@
// Notification id
private static final int NOTIFICATION_ID = 1;
+ // ignore audio data
+ private static final int AUDIO_IGNORED_NUM = 3;
+
// Set audio policy for FM
// should check AUDIO_POLICY_FORCE_FOR_MEDIA in audio_policy.h
private static final int FOR_PROPRIETARY = 1;
@@ -425,37 +428,50 @@
}
class RenderThread extends Thread {
+ private int mCurrentFrame = 0;
+ private boolean isAudioFrameNeedIgnore() {
+ return mCurrentFrame < AUDIO_IGNORED_NUM;
+ }
+
@Override
public void run() {
try {
byte[] buffer = new byte[RECORD_BUF_SIZE];
while (!Thread.interrupted()) {
- boolean render = isRender();
- if (render) {
+ if (isRender()) {
+ if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) {
+ mAudioRecord.startRecording();
+ }
// need rendering
if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
mAudioTrack.play();
}
- if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) {
- mAudioRecord.startRecording();
- }
int size = mAudioRecord.read(buffer, 0, RECORD_BUF_SIZE);
+ // check whether need to ignore first 3 frames audio data from AudioRecord
+ // to avoid pop noise.
+ if (isAudioFrameNeedIgnore()) {
+ mCurrentFrame += 1;
+ Log.d(TAG, "EYES ignore " + mCurrentFrame);
+ continue ;
+ }
byte[] tmpBuf = new byte[size];
System.arraycopy(buffer, 0, tmpBuf, 0, size);
// write to audio track
- mAudioTrack.write(tmpBuf, 0, tmpBuf.length);
- } else {
- // only status wait for render
- // stop all
- if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
- mAudioRecord.stop();
+ if (isRender()) {
+ mAudioTrack.write(tmpBuf, 0, tmpBuf.length);
}
-
+ } else {
+ mCurrentFrame = 0;
// Do not stop audio track to keep the native audio patch
if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) {
mAudioTrack.stop();
}
+ // only status wait for render stop all
+ if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
+ mAudioRecord.stop();
+ }
+
//enableFmAudio(true);
synchronized (mRenderLock) {
mRenderLock.wait();