admin管理员组文章数量:1122847
I wrote an App to record video and audio in a foreground service:
- MainActivity handles all permission's stuff;
- It launches a fragment to be the client (controller) of a foreground LivecycleService;
- When I "click" a button in the client it sends a message to the service and it starts recording video/audio;
- Clicking the button again, it sends a message to the service to stop recording of video/audio;
- Exiting the client inform the service, disconnect and exit;
- If not recording, the service stops itself and is destroyed.
This works as expected except that when recording (video/audio) and the client exits, it stops recording the audio! Restarting the client resumes the audio recording! How can this audio recording stop be prevented?
Some of what I think is pertinent code:
recording=videoCapture.output
.prepareRecording(this, mediaStoreOutputOptions)
.apply {
// Enable Audio in this recording.
// if (PermissionChecker.checkSelfPermission(applicationContext,
// if (PermissionChecker.checkSelfPermission(baseContext,
if (PermissionChecker.checkSelfPermission(this@MyService,
Manifest.permission.RECORD_AUDIO)==PermissionChecker.PERMISSION_GRANTED)
{ // Enables audio to be recorded for this recording.
withAudioEnabled()
}
}
// Start this new recording, and register a lambda VideoRecordEvent listener.
// getMainExecutor: Return an Executor that will run enqueued tasks on the main thread
// associated with this context.
.start(ContextCompat.getMainExecutor(this)) { recordEvent -> ...
I started with no permission check here for RECORD_AUDIO because I already did that in the MainActivity, but withAudioEnabled requires it (why?!).
Thanks for any help/comments.
I tried:
- Several contexts in PermissionChecker.checkSelfPermission as shown in the comments;
- Move the check of for audio permission out of prepareRecording;
- I tried to move all the MainActivity permissions stuff to inside the LifecycleService but I was unable to do that. All I know about that needs to be into an Activity.
本文标签:
版权声明:本文标题:Android, kotlin, camerax: No sound in a foreground LivecycleService recording videoaudio when client exits - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736273142a1923553.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论