1

I am using the CrossMediaManager to play video in my tab download folder , the video play path is file:///storage/emulated/0/Download/DilmahStory.mp4

the problem is that when i move the video page to another page and coming back to the video page the video paused. the requirement is to start the video from the beginning when every time user open the video page.

the video page view model as below

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

I have no idea why the video doesn't start from the beginning when open the vediopage, I will be really grateful if someone can guide me what should I change on the OnPageAppearingCommand() or OnPageDisappearingCommand(), Thank you in advance for your support.

Lennart
  • 9,657
  • 16
  • 68
  • 84

0 Answers0