java - 从服务模拟 YouTube 等应用的暂停/播放
问题描述
我正在尝试全局模拟播放/暂停操作,以便在播放 YouTube 视频时,它会暂停或恢复。
我不确定如何在服务中专门实现这一点。
所以我有这个功能
public static void sendMediaButton(Context context, int keyCode) {
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
context.sendOrderedBroadcast(intent, null);
keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
context.sendOrderedBroadcast(intent, null);
}
我称之为
sendMediaButton(getApplicationContext(), KeyEvent.KEYCODE_MEDIA_PAUSE);
但是在我的服务中,这没有任何作用,YouTube 视频仍在播放。
FWIW,我的应用程序同时具有ACTION_MANAGE_OVERLAY_PERMISSION
权限SYSTEM_ALERT_WINDOW
,因此它仍然可以以最小的限制启动活动等等。
我的问题是:如何在我的服务中模拟播放和暂停操作?
谢谢!
解决方案
推荐阅读
- php - 如何向 wordpress 网站主题添加自定义功能?
- android - Android 深层链接“wc:”方案
- sql - SQL 搜索逗号分隔列表的一部分,在同样有逗号分隔列表的列中
- python - 如何在 Python 中转置二维数组,而不使用内置的 transpose() 函数?
- php - 如何在我的产品发布页面中保存 ACF 选择字段值(位置下拉列表)?
- http - 在客户端超时时终止服务器处理
- mysql - presto create view on CLI 给连接器不支持创建视图错误
- css - CSS文字动画查询
- ios - SwiftUI 点击手势开始/结束动作
- python-3.x - 如何在 Python 中执行 Excel 相对引用公式