public static void updateRecordsData() { var newconn = GetConnection ("WingsRecorder"); var m = newconn.Table<RecordingData> ().OrderByDescending(x=>x.ID).ToList (); var mycontresolv = MainActivity.mycontresol; foreach (var item in m) { var filename = item.filename; var myfile = new Java.IO.File (filename); if (myfile.Exists ()) { item.isFileExist = true; var mystrings = filename.Split (new String[]{ "_" }, StringSplitOptions.RemoveEmptyEntries); var mynumber = string.Join ("", mystrings [mystrings.Length - 2].ToCharArray ().Where (Char.IsDigit)); item.contactNumber = mynumber; var myuri = Android.Net.Uri.WithAppendedPath (ContactsContract.PhoneLookup.ContentFilterUri, Android.Net.Uri.Encode (mynumber)); using (var cursor = mycontresolv.Query (myuri, new string[]{ ContactsContract.Contacts.InterfaceConsts.DisplayName }, null, null, null)) { if (cursor.MoveToFirst ()) { item.contactName = cursor.GetString (cursor.GetColumnIndex (ContactsContract.Contacts.InterfaceConsts.DisplayName)); } else item.contactName = item.contactNumber.ToString (); cursor.Close (); } var my = new MediaMetadataRetriever (); my.SetDataSource (filename); var timerecd = my.ExtractMetadata (MetadataKey.Date); if (timerecd != null) { var timestrings = timerecd.Split (new String[]{ "." }, StringSplitOptions.RemoveEmptyEntries); timestrings = timestrings [0].Split (new String[]{ "T" }, StringSplitOptions.RemoveEmptyEntries); timerecd = timestrings [0] + timestrings [1]; item.callTime = DateTime.ParseExact (timerecd, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture); item.Duration = Convert.ToInt32 (my.ExtractMetadata (MetadataKey.Duration)); } if (filename.Contains ("_OUT")) item.callType = "OUT"; else if (filename.Contains ("_IN")) item.callType = "IN"; if (mynumber.Length > 7) item.filteredContactNumber = mynumber.Substring (mynumber.Length - 8); else item.filteredContactNumber = mynumber; } else { item.isFileExist = false; } newconn.Update (item); } }
public MemoryStream CompressVideo( string sourceFilePath, string destinationFilePath, bool deleteSourceFile ) { if (sourceFilePath == null || destinationFilePath == null) return null; MediaMetadataRetriever media = new MediaMetadataRetriever (); media.SetDataSource ( sourceFilePath ); string videoRotation = media.ExtractMetadata ( MetadataKey.VideoRotation ); XamarinAndroidFFmpeg.FFMpeg ffmpeg = new FFMpeg ( MainApplication.Context, App.DownloadsPath); var onComplete = new MyCommand ((_) => { }); var onMessage = new MyCommand ((message) => { System.Diagnostics.Debug.WriteLine( "---" + message); }); if (videoRotation != null && videoRotation == "90") { string[] cmds = new string[] { "-i", sourceFilePath, "-vcodec", "mpeg4", "-acodec", "aac", "-strict", "-2", "-ac", "1", "-ar", "16000", "-r", "13", "-ab", "32000", "-vf", "transpose=1", "-y", destinationFilePath }; var callbacks = new FFMpegCallbacks (onComplete, onMessage); ffmpeg.Execute (cmds, callbacks); } else { string[] cmds = new string[] { "-i", sourceFilePath, "-vcodec", "mpeg4", "-acodec", "aac", "-strict", "-2", "-ac", "1", "-ar", "16000", "-r", "13", "-ab", "32000", "-y", destinationFilePath }; var callbacks = new FFMpegCallbacks (onComplete, onMessage); ffmpeg.Execute (cmds, callbacks); } if (deleteSourceFile) { Java.IO.File toDel = new Java.IO.File ( sourceFilePath ); toDel.Delete (); } MemoryStream ms = new MemoryStream(); FileStream file = new FileStream( destinationFilePath, FileMode.Open, FileAccess.Read); file.CopyTo ( ms ); file.Close(); return ms; }
private void createImages(HorizontalScrollView view) { MediaMetadataRetriever data = new MediaMetadataRetriever(); data.SetDataSource(filename); int videoLength = Convert.ToInt32(data.ExtractMetadata(MetadataKey.Duration)); #if DEBUG Console.WriteLine("Duration = {0}, videoLength = {1}", data.ExtractMetadata(MetadataKey.Duration), videoLength); #endif LinearLayout linLay = new LinearLayout(context); linLay.Orientation = Android.Widget.Orientation.Horizontal; linLay.LayoutParameters = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent); ShowLightboxDialog(Application.Resources.GetString(Resource.String.videoEditGenerateThumbs)); ImageView imageView = new ImageView(context); imageView.LayoutParameters = new ViewGroup.LayoutParams((int)ImageHelper.convertDpToPixel(55f, context), (int)ImageHelper.convertDpToPixel(55f, context)); #if DEBUG for (int n = 0; n < videoLength; ++n) { using (Bitmap bmp = data.GetFrameAtTime((long)n * 1000, (int)Option.ClosestSync)) { if (bmp != null) Console.WriteLine("frame {0} contains an image", n); } } #endif for (int n = 10; n < /*videoLength*/timeUsed * fps; ++n) { using (Bitmap bmp = data.GetFrameAtTime((long)n, (int)Option.ClosestSync)) { if (bmp != null) { using (Bitmap smBmp = Bitmap.CreateScaledBitmap(bmp, (int)ImageHelper.convertDpToPixel(55f, context), (int)ImageHelper.convertDpToPixel(55f, context), true)) { int m = new int(); m = n; imageView.Tag = m; imageView.Click += (object sender, EventArgs e) => frameClicked(sender, e); imageView.SetImageBitmap(smBmp); } } else imageView.SetBackgroundColor(Color.AliceBlue); } RunOnUiThread(() => linLay.AddView(imageView)); } DismissLightboxDialog(); data.Release(); }
public MemoryStream CreateVideoThumbnail ( string inputVideoPath, string outputImagePath ) { MediaMetadataRetriever media = new MediaMetadataRetriever (); media.SetDataSource ( inputVideoPath ); string videoRotation = media.ExtractMetadata ( MetadataKey.VideoRotation ); XamarinAndroidFFmpeg.FFMpeg ffmpeg = new FFMpeg ( MainApplication.Context, App.DownloadsPath); var onComplete = new MyCommand ((_) => { }); var onMessage = new MyCommand ((message) => { System.Diagnostics.Debug.WriteLine( "---" + message); }); var callbacks = new FFMpegCallbacks (onComplete, onMessage); if (videoRotation != null && videoRotation == "90") { string[] cmds = new string[] { "-i", inputVideoPath, "-ss", "00:00:01.000", "-vf", "transpose=1", outputImagePath }; ffmpeg.Execute (cmds, callbacks); } else { string[] cmds = new string[] { "-i", inputVideoPath, "-ss", "00:00:01.000", outputImagePath }; ffmpeg.Execute (cmds, callbacks); } MemoryStream ms = new MemoryStream (); FileStream stream = new FileStream (outputImagePath, FileMode.Open); stream.CopyTo (ms); return ms; }