如何解决颤振如何滑动audio_service软件包的通知?
当前,关闭通知的唯一方法是按停止按钮。但是我不知道如何用可滑动的“东西”包裹通知小部件。您能告诉我任何适用于此的程序包或我必须用audio_service程序包包装东西的代码吗?
audio_service软件包的发布者是-ryanheise.com
解决方法
作为有用的提示,搜索audio_service的整个文档以找到某个问题的答案的最简单方法是导航到audio_service.dart
文件(包含整个插件),然后搜索单词“刷卡”。您会在AudioService.start
上找到此选项:
/// [androidStopForegroundOnPause] will switch the Android service to a lower
/// priority state when playback is paused allowing the user to swipe away the
/// notification. Note that while in this lower priority state,the operating
/// system will also be able to kill your service at any time to reclaim
/// resources.
然后在BackgroundAudioTask
内:
/// Called on Android when the user swipes away the notification. The default
/// implementation (which you may override) calls [onStop]. Note that by
/// default,the service runs in the foreground state which (despite the name)
/// allows the service to run at a high priority in the background without the
/// operating system killing it. While in the foreground state,the
/// notification cannot be swiped away. You can pass a parameter value of
/// `true` for `androidStopForegroundOnPause` in the [AudioService.start]
/// method if you would like the service to exit the foreground state when
/// playback is paused. This will allow the user to swipe the notification
/// away while playback is paused (but it will also allow the operating system
/// to kill your service at any time to free up resources).
Future<void> onClose() => onStop();
(您可能会发现它比阅读在线HTML文档更容易搜索。)
上面的意思是,您需要将androidStopForegroundOnPause: true
作为参数传递给AudioService.start
,然后在用户滑动时是否要处理除默认行为以外的任何特殊行为(停止服务)离开通知,您可以选择在自己的背景音频任务中覆盖onClose
。没有适用于iOS的版本。
请注意,在播放音频时无法清除Android通知,但上述选项可让您从暂停状态清除通知。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。