播放本地录制视频

问题描述 投票:0回答:1

我只想录制视频,将其复制到本地存储并能够重播。我尝试了许多不同的解决方案。从 VS 在实际设备上调试时效果很好,但一旦应用程序传输到 Apple,我只能得到没有内容的红色矩形。

XAML:

<xct:MediaElement
  BackgroundColor="red"
  x:Name="mediaElement"
  Source="{Binding Video}" 
  ShowsPlaybackControls="True"
  HeightRequest="400"
  HorizontalOptions="Fill"/>

MVVM:

public async void MoveVideo(FileResult fileResult)
{
  var documentsFolder = GetVideoFolderPath();
  var newFile = Path.Combine(documentsFolder, fileResult.FileName);
  using (var stream = await fileResult.OpenReadAsync())
  using (var newStream = File.OpenWrite(newFile))
    await stream.CopyToAsync(newStream);

  var ex = System.IO.File.Exists(Path.Combine(documentsFolder, fileResult.FileName));        // just to validate - returns true
}

public string GetVideoFolderPath()
{
  var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  return documentsFolder;
}

private void CheckVideo() {
  var documentsFolder = _videoService.GetVideoFolderPath();
  var pathAndFile = Path.Combine(documentsFolder, LocalFilePath);
  var b = new System.Uri(pathAndFile).AbsolutePath;
  if(File.Exists(pathAndFile)) 
  {
    Video = MediaSource.FromFile(b);
  }
}

请注意,从 VS 调试时它可以工作并显示视频。如何保证播放?

谢谢!

ios xamarin xamarin.forms
1个回答
0
投票

感谢您的投入。但是,我必须将媒体播放器替换为 MediaManager.Forms,它可以按预期播放文件。

© www.soinside.com 2019 - 2024. All rights reserved.