Detect Corrupted Video

deeeeee2 21 Reputation points
2022-01-05T09:49:55.573+00:00

Hi,

is there anyways to detect the event of video not playing because the video is not in the folder or because it is corrupted ?

When a video is not playing, there is a question pop up with a ok button to dismiss it.

Thank you in advance !!

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-01-06T06:47:37.117+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    If you use this plugin: Plugin.MediaManager.Forms to play the video, when you play the corrupted or nonexistent Video, MediaItemFailed will be executed. You will get exception or message like following code.

       CrossMediaManager.Current.MediaItemFailed += Current_MediaItemFailed;  
           
         
               private void Current_MediaItemFailed(object sender, MediaManager.Media.MediaItemFailedEventArgs e)  
               {  
                    
                   Console.WriteLine(e.Message);  
                   Console.WriteLine(e.Exeption);  
                   
               }  
    

    If you want to detect corrupted video from the video layer, you need to get the video's MD5 value, then read the video file compare the MD5 value. For example, I read AboutAssets.txt from the Assets folder. then compare it.

       public void Compare()  
               {  
                    
                   string content;  
                   AssetManager asset1 = Android.App.Application.Context.Assets;  
                   using (StreamReader sr = new StreamReader(asset1.Open("AboutAssets.txt")))  
                   {  
                       content = sr.ReadToEnd();  
                   }  
         
                   var InPuthash= GetMd5Hash(content);  
                   string hash = "sfsgDGDgds";  
                   var result = VerifyMd5Hash(InPuthash, hash);  
                  
         
               }  
               static string GetMd5Hash(string input)  
               {  
                   using (MD5 md5Hash = MD5.Create())  
                   {  
         
                       // Convert the input string to a byte array and compute the hash.  
                       byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));  
         
                       // Create a new Stringbuilder to collect the bytes  
                       // and create a string.  
                       StringBuilder sBuilder = new StringBuilder();  
         
                       // Loop through each byte of the hashed data   
                       // and format each one as a hexadecimal string.  
                       for (int i = 0; i < data.Length; i++)  
                       {  
                           sBuilder.Append(data[i].ToString("x2"));  
                       }  
         
                       // Return the hexadecimal string.  
                       return sBuilder.ToString();  
                   }  
               }  
         
               // Verify a hash against a string.  
               static bool VerifyMd5Hash(string input, string hash)  
               {  
                   // Hash the input.  
                   string hashOfInput = GetMd5Hash(input);  
         
                   // Create a StringComparer an compare the hashes.  
                   StringComparer comparer = StringComparer.OrdinalIgnoreCase;  
         
                   return 0 == comparer.Compare(hashOfInput, hash);  
         
               }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. deeeeee2 21 Reputation points
    2022-01-06T08:33:43.74+00:00

    Hi thanks a lot for your fast answer !!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.