TMSFNCWXVideoPlayer does not play under System.IOUtils.TPath.GetDocumentsPath

Delphi 11.3 FMX compile for IOS64

  1. The TMSFNCWXVideoPlayer does not play the mp4 file under System.IOUtils.TPath.GetDocumentsPath.
  2. I always integrate the mediaplayer and the mp4 file run.

//-------------
VideoFilePath := IncludeTrailingPathDelimiter(System.IOUtils.TPath.GetDocumentsPath) + 'bilder' + PathDelim ;
TMSFNCWXVideoPlayer1.URL := VideoFilePath + 'test1.mp4';
MediaPlayer1.FileName := VideoFilePath + 'test1.mp4';

ShowMessage(VideoFilePath + 'test1.mp4') ;
MediaPlayer1.Play;
TMSFNCWXVideoPlayer1.Play ;
// --------
3. If I copy the mp4 to System.IOUtils.TPath.GetTempPath the TMSFNCWXVideoPlayer1 play the mp4 file

// -----------------------------
TempVideoFilePath := System.IOUtils.TPath.combine(System.IOUtils.TPath.GetTempPath, 'video.mp4');
AResultStream.Position := 0; // Reset stream position to the beginning
with TFileStream.Create(TempVideoFilePath, fmCreate) do
try
CopyFrom(AResultStream, AResultStream.Size);
finally
Free;
end;
TMSFNCWXVideoPlayer1.URL := TempVideoFilePath;
TMSFNCWXVideoPlayer1.Play;
// ---------------------------
Can you help? What is the problem?

Hi,

you might have to replace the \ with /.

      path := OpenDialog1.Files[0];
      vPlayer.URL := stringreplace(path, '\','/', [rfReplaceAll]);
it doesn't work. Same effect mediaplayer1 play and TMSFNCWXVideoPlayer1 not.

procedure TForm2.BtnPlay1Click(Sender: TObject);
var  VideoFilePathnew: String  ;
begin
  VideoFilePath     := IncludeTrailingPathDelimiter(System.IOUtils.TPath.GetDocumentsPath)  + 'bilder' + PathDelim + 'test1.mp4';
  VideoFilePathnew  := stringreplace(VideoFilePath, '\','/', [rfReplaceAll]);

  TMSFNCWXVideoPlayer1.URL := VideoFilePathnew;
  MediaPlayer1.FileName    := VideoFilePath ;

  Memo1.Lines.Add('--VideoFilePath--');
  Memo1.Lines.Add(VideoFilePath);

  Memo1.Lines.Add('--VideoFilePathnew--');
  Memo1.Lines.Add(VideoFilePathnew);

  TMSFNCWXVideoPlayer1.Play ;
  MediaPlayer1.Play;
end;

from memo1:
--VideoFilePath--
/var/mobile/Containers/Data/Application/97142320-FCOA-47C5-8805-65A98DF9F2AC/Documents/bilder/test1.mp4
--VideoFilePathnew--
/var/mobile/Containers/Data/Application/97142320-FCOA-47C5-8805-65A98DF9F2AC/Documents/bilder/test1.mp4

if I replace 
VideoFilePathnew  := stringreplace(VideoFilePath, '\','/', [rfReplaceAll]) with
VideoFilePathnew  := stringreplace(VideoFilePath, '/','\', [rfReplaceAll])

Also doesn't run.
from memo1:
--VideoFilePath--
/var/mobile/Containers/Data/Application/97142320-FCOA-47C5-8805-65A98DF9F2AC/Documents/bilder/test1.mp4
--VideoFilePathnew--
\var\mobile\Containers\Data\Application\97142320-FCOA-47C5-8805-65A98DF9F2AC\Documents\bilder\test1.mp4

Attention:
with GetTempPath it works!!!
VideoFilePathnew := System.IOUtils.TPath.GetTempPath + PathDelim + 'test1.mp4';

Hi,

It's not clear why the video is not playing from the Documents folder.

Are you saving the video into the Documents folder first and try to open it after? Can it successfully write the video there and you are able to access it outside of TTMSFNCWXVideoPlayer?

You are saying it works with GetTempPath, what is the output of that?

Yes, I copy first the video (1), and then play it (2) 

(1) I get the video and play it from System.IOUtils.TPath.GetTempPath (it works fine)

procedure TForm2.UpdateViewControls;
var
  PickerResult: TTMSFMXNativePHPickerResult;
begin
  BtnPrev.Enabled := VideoIdx > 0; // Enable the Previous button if there's a previous item
  BtnNext.Enabled := (VideoIdx >= 0) and (VideoIdx < TMSFMXNativePHPickerViewControllerPopup1.Results.Count - 1); // Enable the Next button if there's a next item

  // Clear the previous content
  TMSFNCWXVideoPlayer1.URL := '';

  if (VideoIdx >= 0) and (VideoIdx < TMSFMXNativePHPickerViewControllerPopup1.Results.Count) then
  begin
    PickerResult := TMSFMXNativePHPickerViewControllerPopup1.Results[VideoIdx];
      // Load video from stream
      LoadVideoFromStream(PickerResult.Stream);
      TMSFNCWXVideoPlayer1.Visible := True;
      Label1.Text := 'Video ' + IntToStr(VideoIdx + 1) + ' of ' + IntToStr(TMSFMXNativePHPickerViewControllerPopup1.Results.Count);
  end
  else
    Label1.Text := 'No video selected.';
end;

procedure TForm2.LoadVideoFromStream(AResultStream: TMemoryStream);
var
  TempVideoFilePath : string;
begin
  // Create a temporary file name
  TempVideoFilePath := System.IOUtils.TPath.combine(System.IOUtils.TPath.GetTempPath, 'test1.mp4');
  // Save the stream to the temporary file
  AResultStream.Position := 0; // Reset stream position to the beginning
  with TFileStream.Create(TempVideoFilePath, fmCreate) do
  try
    CopyFrom(AResultStream, AResultStream.Size);
  finally
    Free;
  end;

  DeleteFilesWithPattern(Spielverzeichnis, '*.mp4');  // delete all *.mp4 under System.IOUtils.TPath.GetDocumentsPath)  + 'bilder'
  System.IOUtils.TFile.Copy(System.IOUtils.TPath.GetTempPath + PathDelim + 'test1.mp4', Spielverzeichnis + PathDelim + 'test1.mp4') ;   // copy from TPath.GetTempPath to  System.IOUtils.TPath.GetDocumentsPath)  + 'bilder'

  Memo1.Lines.add(TempVideoFilePath) ;
  // Set the URL property to the temporary file
  TMSFNCWXVideoPlayer1.URL := TempVideoFilePath;
  TMSFNCWXVideoPlayer1.Play;
end;

(2) i want to run it under System.IOUtils.TPath.GetDocumentsPath)  + 'bilder' ( not run with TMSFNCWXVideoPlayer1 but run with mediaplayer1) 

procedure TForm2.BtnPlay1Click(Sender: TObject);
var  VideoFilePathnew: String  ;
begin
  VideoFilePath     := IncludeTrailingPathDelimiter(System.IOUtils.TPath.GetDocumentsPath)  + 'bilder' + PathDelim + 'test1.mp4';
  VideoFilePathnew  := stringreplace(VideoFilePath, '\','/', [rfReplaceAll]);

  TMSFNCWXVideoPlayer1.URL := VideoFilePathnew;
  MediaPlayer1.FileName    := VideoFilePath ;

  Memo1.Lines.Add('--VideoFilePath--');
  Memo1.Lines.Add(VideoFilePath);

  Memo1.Lines.Add('--VideoFilePathnew--');
  Memo1.Lines.Add(VideoFilePathnew);

  TMSFNCWXVideoPlayer1.Play ;
  MediaPlayer1.Play;
end;

No Idea???

Hi,

Sorry, it has been very busy. This issue is more complex than we initially thought. We will need more time to investigate it.