I'm playing around with Android's TTS features and the TextToSpeech class has this method to set a listener which gets notified once the TextToSpeech has finished playing:
public int setOnUtteranceCompletedListener(TextToSpeech.OnUtteranceCompletedListener listener)
But the OnUtteranceCompletedListener
is defined as public abstract class
. As my MainActivity
already extends Activity, it can't extend OnUtteranceCompletedListener
as well. I could use the older method with a OnUtteranceCompletedListener
, but this is deprecated:
public int setOnUtteranceCompletedListener (TextToSpeech.OnUtteranceCompletedListener listener)`
Why is OnUtteranceCompletedListener
not defined as public static interface
? I'm thinking to write my own UtteranceProgressListenerImpl
, which will then just call the MainActivity
s onDone
method. Is this the proper way or is there a better/cleaner alternative?
private class UtteranceProgressListenerImpl extends UtteranceProgressListener {
private MainActivity mainActivity;
UtteranceProgressListenerImpl(MainActivity mA) {
mainActivity = mA;
}
@Override
public void onDone(String utteranceId) {
mainActivity.onDone(utteranceId);
}
@Override
public void onError(String utteranceId) { /* empty */ }
@Override
public void onStart(String utteranceId) { /* empty */ }
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…