Skip to content

Commit dac809c

Browse files
committed
audiobook: swap tts rate bar widget for pos+duration display
1 parent b985896 commit dac809c

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

android/res/layout/tts_toolbar.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,19 @@
187187
android:layout_marginRight="2dip"
188188
android:layout_marginBottom="5dip"
189189
android:layout_weight="1" />
190+
191+
<TextView
192+
android:id="@+id/tts_lbl_audio_progress"
193+
android:typeface="monospace"
194+
android:textSize="14sp"
195+
android:layout_width="0dip"
196+
android:layout_height="wrap_content"
197+
android:layout_marginLeft="5dip"
198+
android:layout_marginTop="0dip"
199+
android:layout_marginRight="5dip"
200+
android:layout_marginBottom="0dip"
201+
android:layout_weight="1"
202+
android:text="" />
203+
</LinearLayout>
190204
</LinearLayout>
191205
</LinearLayout>

android/src/org/coolreader/crengine/TTSToolbarDlg.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class TTSToolbarDlg implements Settings {
7575
private final ImageButton forwardButton;
7676
private final ImageButton stopButton;
7777
private final ImageButton optionsButton;
78+
private final TextView mAudioProgressTextView;
7879
private final TextView mVolumeTextView;
7980
private final TextView mSpeedTextView;
8081
private final SeekBar mSbSpeed;
@@ -195,6 +196,30 @@ private SentenceInfo fetchSelectedSentenceInfo() {
195196
return null;
196197
}
197198

199+
private String formatDurationHHHMMSS(double duration) {
200+
return String.format(Locale.getDefault(), "%3d:%02d:%02d",
201+
((int) duration) / 60 / 60,
202+
((int) duration) / 60 % 60,
203+
((int) duration) % 60);
204+
}
205+
206+
private void setAudioBookProgressDisplay(SentenceInfo sentenceInfo) {
207+
if(sentenceInfo == null){
208+
mAudioProgressTextView.setVisibility(View.GONE);
209+
mAudioProgressTextView.setText("");
210+
211+
mSbSpeed.setVisibility(View.VISIBLE);
212+
}else{
213+
mAudioProgressTextView.setVisibility(View.VISIBLE);
214+
mAudioProgressTextView.setText(String.format(Locale.getDefault(),
215+
"%s / %s",
216+
formatDurationHHHMMSS(sentenceInfo.startTimeInBook),
217+
formatDurationHHHMMSS(sentenceInfo.totalBookDuration)));
218+
219+
mSbSpeed.setVisibility(View.GONE);
220+
}
221+
}
222+
198223
/**
199224
* Select next or previous sentence. ONLY the selection changes and the specified callback is called!
200225
* Not affected to speech synthesis process.
@@ -211,11 +236,14 @@ public void onNewSelection(Selection selection) {
211236
mCurrentSelection = selection;
212237
if(allowUseAudiobook){
213238
SentenceInfo sentenceInfo = fetchSelectedSentenceInfo();
239+
setAudioBookProgressDisplay(sentenceInfo);
214240
if(sentenceInfo != null && sentenceInfo.audioFile != null){
215241
mTTSControl.bind(ttsbinder -> {
216242
ttsbinder.setAudioFile(sentenceInfo.audioFile, sentenceInfo.startTime);
217243
});
218244
}
245+
}else{
246+
setAudioBookProgressDisplay(null);
219247
}
220248
if (null != callback)
221249
callback.onNewSelection(mCurrentSelection);
@@ -561,6 +589,11 @@ public TTSToolbarDlg(CoolReader coolReader, ReaderView readerView, TTSControlSer
561589
}));
562590
stopButton.setOnClickListener(v -> stopAndClose());
563591

592+
593+
// setup audiobook speed && volume seek bars
594+
mAudioProgressTextView = panel.findViewById(R.id.tts_lbl_audio_progress);
595+
mAudioProgressTextView.setVisibility(View.GONE);
596+
564597
// setup speed && volume seek bars
565598
mVolumeTextView = panel.findViewById(R.id.tts_lbl_volume);
566599
mSpeedTextView = panel.findViewById(R.id.tts_lbl_speed);

0 commit comments

Comments
 (0)