Jump to content
Michele

[Android] Odd problem with TMediaplayer

Recommended Posts

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 by Michele

Share this post


Link to post
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
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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×