0

I am using Xamarin essential using Multipicker while choosing corrupted video its also selected in the Media list when upload time it showing setdatasource failed. How to detect when choosing at time video is corrupted or any other option

result = await Xamarin.Essentials.FilePicker.PickMultipleAsync(new Xamarin.Essentials.PickOptions
                                        {
                                            FileTypes = Xamarin.Essentials.FilePickerFileType.Videos,
                                            PickerTitle = "Please pick a videos"
                                        });

1 Answer 1

0

If you want to detect corrupted video while picking video, you could compare the MD5 value.

But on this way, you need to have correct the MD5 value. For example, i put the correct MD5 value in .txt file of Assets folder and then get the MD5 value when picking video and 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);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.