[MAUI]When I use the AudioTrack.Write() ,it stuck the main thread

studio XFE 95 Reputation points
2023-08-30T22:46:07.1933333+00:00

I created an AudioTrack object named audioTrack, and use the audioTrack.Play(), Then in an Event I use the audioTrack.Write() method, and it stuck the MainThread,

I have try to use the async, but it doesn't help.

I also try to use Task.Run() to created new task,but it create so much task threads and cause the program broken.

What should I do?

User's image

User's image

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-08-31T07:25:43.7066667+00:00

    You can add fourth attribute WriteMode.NonBlocking in the Writemethod. By the way, when you execute the write method, you can do it inHandlerThread.

    As Note: please don't make a screenshot about your code, you can copy your code here directly.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.