0

I developed an Android program using FireMonkey. This program has one TTabItem. I use TMediaPlayerControl to play videos under a TabItem. During the playback process, I switch the TabItem, stop and hide the player. In this case, it is easy to happen. The black box doesn't disappear, I don't know why.

I hope that when playing the video, switching TabItem will not cause a black box to appear. That is to say, the player interface is not hidden successfully. The code is as follows:

player1->Stop();
playCtrl1->Visible = false;
tabControl1->ActiveTab = tabItem1;
2
  • Is there any way to avoid this?
    – andy
    Commented Sep 7 at 3:42
  • May I provide it here? I don't have permission to view this read the bug report
    – andy
    Commented Sep 8 at 1:48

1 Answer 1

0

According to bug #RSS-978, TMediaPlayer on Android can create more than 1 platform player, but will leak them. So perhaps you are seeing a leaked player not being hidden.

The bug report offers the following workaround for the leaking. Maybe it will fix the hiding issue, too.

The reason for the leak is in "source\fmx\FMX.Media.Android.pas". There FMX Delphi creates the player twice for each video "TJMediaPlayer.JavaClass.init". Once in "procedure TAndroidVideo.RetreiveVideoSize" to just get the size of the video picture. And the second time in "constructor TAndroidMedia.Create", then to play the video file already .

The first time they forgot to call "MediaPlayer.release" in "RetreiveVideoSize". Because of which the resources of the media component created in the operating system are not released. On some Android devices the application crashes.

Solution: to patch "FMX.Media.Android.pas" by yourself. In "procedure TAndroidVideo.RetreiveVideoSize" add a call to "MediaPlayer.release".

procedure TAndroidVideo.RetreiveVideoSize;
var
  MediaPlayer: JMediaPlayer;
begin
  MediaPlayer := TJMediaPlayer.JavaClass.init; 
  MediaPlayer.setDataSource(StringToJString(FileName));
  MediaPlayer.prepare;
  FVideoSize := TSize.Create(MediaPlayer.getVideoWidth, MediaPlayer.getVideoHeight);
  MediaPlayer.release; // !!!!!!!  add this line   !!!!!!!
  MediaPlayer := nil;
end;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.