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

studio XFE 0 Reputation points

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

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

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 54,166 Reputation points Microsoft Vendor

    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.