Looper 线程问题?但不使用动画师 [英] Looper threads issue? But not using Animator

查看:26
本文介绍了Looper 线程问题?但不使用动画师的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running a loop to SynthesizeToFile (in this example I will run the loop 10 times)

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

        }       

我正在将 SetOnUtteranceProgressListener 设置为 SetOnUtteranceProgressListener1 如下

I am setting up SetOnUtteranceProgressListener to SetOnUtteranceProgressListener1 which is the following

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 个计数,这意味着这是最后一个要处理的文件并使一些控件可见,例如以下

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

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

        }

我得到的错误如下

Animator 只能在 Looper 线程上运行

Animators may only be run on Looper threads

当它点击FloatingActionButton FAB = FindViewById(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?

推荐答案

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

Place your UI changes within a RunOnUithread Action:

即.

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

这篇关于Looper 线程问题?但不使用动画师的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆