Looper线程问题?但不使用 Animator

Looper threads issue? But not using Animator

我正在运行循环到SynthesizeToFile(在这个例子中我将运行循环10次)

for(int i = 0; i< 10; i++)
{
    textToSpeech.SynthesizeToFile("SOME TEXT", null, new Java.IO.File(System.IO.Path.Combine(documentsPath, i.ToString() + "_audio.wav")), i.ToString());
}

正在初始化TTS

void TextToSpeech.IOnInitListener.OnInit(OperationResult status)
        {
            try
            {
                Voice voiceobj = new Voice("en-us-x-sfg#female_2-local", Java.Util.Locale.English, VoiceQuality.VeryHigh, VoiceLatency.VeryHigh, false, null);
                textToSpeech.SetVoice(voiceobj);


                if (status == OperationResult.Error)
                {
                    textToSpeech.SetLanguage(Java.Util.Locale.Default);
                }

                if (status == OperationResult.Success)
                {
                    textToSpeech.SetLanguage(Java.Util.Locale.English);
                    textToSpeech.SetOnUtteranceProgressListener(new UtteranceProgressListener1(this));
                    Log.Info("101029", "Initialised successfully");
                }
            }
            catch (Exception X)
            {
                Log.Info("101028", "TTF Error? " + X.Message);
            }

        }       

我正在设置 SetOnUtteranceProgressListenerSetOnUtteranceProgressListener1 也就是下面的

public class UtteranceProgressListener1 : UtteranceProgressListener
        {
            ReadArticle _parent;
            int total = 0;

            public UtteranceProgressListener1(ReadArticle p_parent)
            {
                _parent = p_parent;
            }

            public override void OnStart(String utteranceId)
            {

            }

            public override void OnError(String utteranceId)
            {
                Log.Info("101029", "OnError called");
            }

            public override void OnDone(String utteranceId)
            {
                Log.Info("101029", "OnDone: " + total.ToString());
                total++;
                _parent.AudioConvertionResults(total);
            }
        }

每次当它是 OnDone 时,我调用一个函数,该函数基本上只检查它是否是第 10 个计数,这意味着这是最后一个要处理的文件并使一些控件可见,例如以下

    public bool AudioConvertionResults(int CompInt)
            {
                Log.Info("101029", "ComInt: " + CompInt.ToString() );

                if (CompInt >= 10)
                {
                    try
                    {                  
                        Log.Info("101029", "Triggered at " + CompInt.ToString());
                FloatingActionButton FAB = FindViewById<FloatingActionButton>(Resource.Id.fab);
                    FAB.Visibility = ViewStates.Visible;
                    }
                    catch(Exception X)
                    {
                        Log.Info("101029", "Error Triggering? "+X.Message);
                    return fasle;
                    }
                retuen true;

                }
                else
                {
                    Log.Info("101029", "DID NOT Trigger at " + 
                CompInt.ToString());
                return fasle;
                }

        }

我得到的错误如下

Animators may only be run on Looper threads

当它击中 FloatingActionButton FAB = FindViewById<FloatingActionButton>(Resource.Id.fab);

我也试过让它成为一个全局变量,但仍然没有成功。

我想我把事情搞砸了,知道我该怎么做吗?

将您的 UI 更改放在 RunOnUithread 操作中:

RunOnUiThread(() => 
{
    FloatingActionButton FAB = FindViewById<FloatingActionButton>(Resource.Id.fab);
    FAB.Visibility = ViewStates.Visible;
});