Michele 0 Posted July 19, 2021 (edited) Hi there! I'm facing a quite off problem... On a very easy Android/Delphi App i've a tmemo, a tbutton and a tmediaplayer. On the OnClick of the button i do this: memo.Lines.Add('blablabla'); MediaPlayer1.FileName := System.IOUtils.TPath.Combine(TPath.GetDocumentsPath, 'a.mp3'); //playing an internal resource MediaPlayer1.Play; The problem is that "blablabla" is written on the memo only after Mediaplayer finishes playing the file...very very odd! Any ideas? I'm using Delphi 10.3 Community Edition Edited July 19, 2021 by Michele Share this post Link to post
Remy Lebeau 1436 Posted July 19, 2021 6 hours ago, Michele said: The problem is that "blablabla" is written on the memo only after Mediaplayer finishes playing the file...very very odd! That implies that Play() is acting synchronously, not exiting until the audio is finished, thus blocking the main thread from rendering UI updates. Is that actually the case? It should be running asynchronously instead. Share this post Link to post
Rollo62 539 Posted July 20, 2021 16 hours ago, Remy Lebeau said: That implies that Play() is acting synchronously, not exiting until the audio is finished, thus blocking the main thread from rendering UI updates. Is that actually the case? It should be running asynchronously instead. I had the same thought when reading this. In my app I can use TMediaPlayer to play files without blocking, even several TMediaPlayer could play in parallel You could try to decouple the "Play" method, to ensure that the Memo is forced update first. If that still delays the display, then probably something is blocking somewhere else. memo.Lines.Add('blablabla'); MediaPlayer1.FileName := System.IOUtils.TPath.Combine(TPath.GetDocumentsPath, 'a.mp3'); //playing an internal resource TThread.ForceQueue( nil, procedure begin MediaPlayer1.Play; end ); Share this post Link to post
Michele 0 Posted July 20, 2021 1 hour ago, Rollo62 said: I had the same thought when reading this. In my app I can use TMediaPlayer to play files without blocking, even several TMediaPlayer could play in parallel You could try to decouple the "Play" method, to ensure that the Memo is forced update first. If that still delays the display, then probably something is blocking somewhere else. memo.Lines.Add('blablabla'); MediaPlayer1.FileName := System.IOUtils.TPath.Combine(TPath.GetDocumentsPath, 'a.mp3'); //playing an internal resource TThread.ForceQueue( nil, procedure begin MediaPlayer1.Play; end ); Great!!!!!!!!!!!!!! This works perfectly! Many many thanks!!!!!!!!!!!! Share this post Link to post
Rollo62 539 Posted July 20, 2021 Strange, I would investigate why and where its blocking in the first test. Share this post Link to post
Michele 0 Posted July 20, 2021 Just now, Rollo62 said: Strange, I would investigate why and where its blocking in the first test. Sure, as soon as i have a little bit more time to investigare! Thank you! Share this post Link to post