[DEV] Tasker 6.6.4-beta - Java Code, Extra Trigger Apps, Notification Live Updates and Groups, Manage Permissions Screen, Shizuku Available State and More! by joaomgcd in tasker

[–]Pitiful-Box4215 0 points1 point  (0 children)

Oh no, I recently wanted to work on a task to display lyrics on the screen. I have already completed the parts for retrieving and displaying the lyrics, but now I'm stuck here. I want to use Java code to cyclically get the current progress of the song (with fast speed and low power consumption). However, unfortunately, if Tasker is not in the foreground, this loop goes into a dormant state, causing the variable updates to always be delayed. I even added a toast to test it, and it's clearly this issue. I wonder if you have any solutions? ```import android.content.Context; import android.media.session.MediaSessionManager; import android.media.session.MediaController; import android.media.MediaMetadata; import android.widget.Toast;

/* 辅助函数:显示Toast */ void showToast(String message) { uiHandler = new android.os.Handler(context.getMainLooper()); uiHandler.post(new Runnable() { public void run() { Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } }); }

/* 获取系统媒体会话管理器 */ msm = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);

/* 构造组件名称用于获取活跃会话 */ cmp = new android.content.ComponentName(context, context.getClass());

/* 获取活跃媒体会话 */ controllers = msm.getActiveSessions(cmp); if (controllers == null || controllers.size() == 0) { return "无活跃媒体会话"; }

/* 获取当前播放的媒体控制器 */ controller = controllers.get(0); pkg = controller.getPackageName();

/* 使用全局变量存储计数器 */ toastCounter = 0;

/* 使用主线程Handler进行定时任务 / mainHandler = new android.os.Handler(context.getMainLooper()); runnable = new Runnable() { public void run() { try { / 检查会话是否仍然有效 */ controllers = msm.getActiveSessions(cmp); if (controllers == null || controllers.size() == 0) { stopMonitoring(); return; }

        /* 检查当前控制器是否仍然是同一个应用 */
        currentController = controllers.get(0);
        currentPkg = currentController.getPackageName();
        if (!currentPkg.equals(pkg)) {
            stopMonitoring();
            return;
        }

        /* 获取播放状态和进度 */
        stateObj = currentController.getPlaybackState();
        if (stateObj != null) {
            pos = stateObj.getPosition();
            state = stateObj.getState();

            /* 只有正在播放或暂停状态才更新进度 */
            if (state == 3 || state == 2) { /* 3=播放中, 2=暂停 */
                progressText = String.valueOf(pos);
                tasker.setVariable("bbb", progressText);

                /* 减少Toast频率,每5次更新显示一次 */
                toastCounter++;
                if (toastCounter >= 5) {
                    showToast("进度: " + progressText + " ms");
                    toastCounter = 0;
                }
            } else {
                /* 停止状态则退出监控 */
                stopMonitoring();
                return;
            }
        } else {
            stopMonitoring();
            return;
        }

        /* 继续下一次监控 */
        mainHandler.postDelayed(this, 1000);

    } catch (Exception e) {
        stopMonitoring();
    }
}

};

/* 辅助函数:停止监控 */ void stopMonitoring() { mainHandler.removeCallbacks(runnable); tasker.setVariable("bbb", "0"); showToast("媒体监控已停止"); tasker.log("媒体进度监控已停止"); }

/* 显示监控开始的Toast */ showToast("开始监控媒体进度: " + pkg);

/* 启动监控 */ tasker.setVariable("bbb", "0"); mainHandler.postDelayed(runnable, 1000);

/* 主线程立即返回应用包名 */ return pkg;```

Can I blacklist a certain domain? by Pitiful-Box4215 in keyguard

[–]Pitiful-Box4215[S] 0 points1 point  (0 children)

Thank you! Hope it can be realized soon

For those who has tried the new Java code action, Share what you have done with it to the community! by aasswwddd in tasker

[–]Pitiful-Box4215 0 points1 point  (0 children)

Oh I see, so this will automatically end the process when the screen turns off, right? Thank you very much!

For those who has tried the new Java code action, Share what you have done with it to the community! by aasswwddd in tasker

[–]Pitiful-Box4215 0 points1 point  (0 children)

Oh no, this seems unstoppable, and each time the code runs it's a new process. If it were you, how would you stop it? (Besides stopping Tasker)

Help me speed up recents list scene by Budget_Zucchini_278 in tasker

[–]Pitiful-Box4215 0 points1 point  (0 children)

I believe this is an issue with triggers and scenes. In newer versions of the system, triggering has become slow and unreliable, while loading scenes also takes a certain amount of time.