我正在使用 CrossMediaManager 在我的标签下载文件夹中播放视频,视频播放路径是file:///storage/emulated/0/Download/DilmahStory.mp4
问题是当我将视频页面移动到另一个页面并返回视频页面时,视频暂停了。要求是每次用户打开视频页面时从头开始播放视频。
视频页面查看模型如下
public class GuestVideoViewModel : ContextViewModelBase
{
private string videoUrl = "file:///storage/emulated/0/Download/DilmahStory.mp4";
private TimeSpan seekTime;
public GuestVideoViewModel(IAppContext context) : base(context)
{
Title = "Guest Vedio Page";
ActionCommand = new Command(OnActionCommand);
PageAppearingCommand = new Command(OnPageAppearingCommand);
PageDisappearingCommand = new Command(OnPageDisappearingCommand);
}
public string GotoMenuName { get; set; } = "START ORDER";
public ICommand ActionCommand { get; }
private void OnActionCommand()
{
Navigator.PushAsync<DashboardMainFirstViewMode>();
}
private async void OnPageDisappearingCommand()
{
seekTime = CrossMediaManager.Current.Position;
await CrossMediaManager.Current.Stop();
CrossMediaManager.Current.StatusChanged -= CurrentOnStatusChanged;
//
}
private async void OnPageAppearingCommand()
{
if (await GetStoragePermisson())
{
CrossMediaManager.Current.StatusChanged += CurrentOnStatusChanged;
await CrossMediaManager.Current.Play(videoUrl, MediaFileType.Video);
}
}
private void CurrentOnStatusChanged(object sender, StatusChangedEventArgs e)
{
Debug.WriteLine($"MediaManager Status: {e.Status}");
}
private async Task<bool> GetStoragePermisson()
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
if (status != PermissionStatus.Granted)
{
var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });
status = results[Permission.Storage];
}
return status == PermissionStatus.Granted;
}
}
}
我不知道为什么打开视频页面时视频没有从头开始,如果有人可以指导我应该在OnPageAppearingCommand()
or上更改什么,我将非常感激OnPageDisappearingCommand()
,提前感谢您的支持。