简体   繁体   English

弯针线程问题? 但不使用Animator

[英]Looper threads issue? But not using Animator

I am running a loop to SynthesizeToFile (in this example I will run the loop 10 times) 我正在运行到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 Initialising 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);
            }

        }       

I am setting up SetOnUtteranceProgressListener to SetOnUtteranceProgressListener1 which is the following 我将SetOnUtteranceProgressListener设置为SetOnUtteranceProgressListener1 ,如下所示

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);
            }
        }

Every time when it is OnDone I call a function which basically just checks if it a 10th count, means this is the last file to process and make some controls visible such as following 每次当它是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;
                }

        }

The error I get is the following 我得到的错误是以下

Animators may only be run on Looper threads 动画师只能在Looper线程上运行

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

I also tried to make this a global variable but still no luck. 我也尝试将其设置为全局变量,但还是没有运气。

I think I am messing up something bad, any idea what should I do? 我想我弄糟了一些不好的东西,知道该怎么办吗?

Place your UI changes within a RunOnUithread Action: 将您的UI更改放在RunOnUithread操作中:

ie. 即。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM