FMX MediaPlayer Access Violation (Delphi)

  

Using ResourceStream to extract a file (*.3gp) from a resource and play it in TMediaPlayer.
The sound plays fine, but after playing ended there is a “Access Violation at address..” error.

Access violation at address A1A38F12, accessing address 56166A98.

Here is the code:

unit Unit2;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Media,
FMX.Controls.Presentation, FMX.StdCtrls, IOUtils, FMX.AndroidLike.Toast;

type
TForm2 = class(TForm)
Button1: TButton;
MediaPlayer1: TMediaPlayer;
Toast1: TToast;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
loc: string;

implementation

{$R *.fmx}

procedure TForm2.Button1Click(Sender: TObject);
var
ResStream: TResourceStream;
AppPath: string;
Bottom: TAlignLayout;
Top: TAlignLayout;
begin
ResStream := TResourceStream.Create(HInstance, ‘sound’, RT_RCDATA);
try
ResStream.Position := 0;
AppPath := TPath.GetHomePath;
loc := TPath.Combine(AppPath, ‘sound.3gp’);
ResStream.SaveToFile(loc);
finally
ResStream.Free;
end;
MediaPlayer1.Clear();
MediaPlayer1.FileName := loc;

MediaPlayer1.Play();

DeleteFile(loc);
Toast1.ToastBoxAlign := Bottom;
Toast1.Now(‘Hello World!’);

end;

Developing an Android app.

Comments are closed.