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?
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;