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

studio XFE 65 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

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,962 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,311 Reputation points Microsoft Vendor
    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