internal static string GetFilePath(this StoreMediaOptions self, string rootPath) { bool isPhoto = !(self is StoreVideoOptions); string name = (self != null) ? self.Name : null; if (String.IsNullOrWhiteSpace(name)) { string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss"); if (isPhoto) { name = "IMG_" + timestamp + ".jpg"; } else { name = "VID_" + timestamp + ".mp4"; } } string ext = Path.GetExtension(name); if (ext == String.Empty) { ext = ((isPhoto) ? ".jpg" : ".mp4"); } name = Path.GetFileNameWithoutExtension(name); string folder = Path.Combine(rootPath ?? String.Empty, (self != null && self.Directory != null) ? self.Directory : String.Empty); return(Path.Combine(folder, name + ext)); }
private Intent CreateMediaIntent(int id, string type, string action, StoreMediaOptions options, bool tasked = true) { Intent pickerIntent = new Intent(context, typeof(MediaPickerActivity)); pickerIntent.PutExtra(MediaPickerActivity.ExtraId, id); pickerIntent.PutExtra(MediaPickerActivity.ExtraType, type); pickerIntent.PutExtra(MediaPickerActivity.ExtraAction, action); pickerIntent.PutExtra(MediaPickerActivity.ExtraTasked, tasked); if (options != null) { pickerIntent.PutExtra(MediaPickerActivity.ExtraPath, options.Directory); pickerIntent.PutExtra(MediaStore.Images.ImageColumns.Title, options.Name); var vidOptions = (options as StoreVideoOptions); if (vidOptions != null) { pickerIntent.PutExtra(MediaStore.ExtraDurationLimit, (int)vidOptions.DesiredLength.TotalSeconds); pickerIntent.PutExtra(MediaStore.ExtraVideoQuality, (int)vidOptions.Quality); } } return(pickerIntent); }
private void VerifyOptions(StoreMediaOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (Path.IsPathRooted(options.Directory)) { throw new ArgumentException("options.Directory must be a relative path", "options"); } }
private void VerifyOptions(StoreMediaOptions options) { if (options == null) { throw new ArgumentNullException("options"); } //if (!Enum.IsDefined (typeof(MediaFileStoreLocation), options.Location)) // throw new ArgumentException ("options.Location is not a member of MediaFileStoreLocation"); //if (options.Location == MediaFileStoreLocation.Local) //{ if (options.Directory != null && Path.IsPathRooted(options.Directory)) { throw new ArgumentException("options.Directory must be a relative path", "options"); } //} }
internal static string GetUniqueFilepath(this StoreMediaOptions self, string rootPath, Func <string, bool> checkExists) { string path = self.GetFilePath(rootPath); string folder = Path.GetDirectoryName(path); string ext = Path.GetExtension(path); string name = Path.GetFileNameWithoutExtension(path); string nname = name + ext; int i = 1; while (checkExists(Path.Combine(folder, nname))) { nname = name + "_" + (i++) + ext; } return(Path.Combine(folder, nname)); }
internal static void VerifyOptions(this StoreMediaOptions self) { if (self == null) { throw new ArgumentNullException("options"); } //if (!Enum.IsDefined (typeof(MediaFileStoreLocation), options.Location)) // throw new ArgumentException ("options.Location is not a member of MediaFileStoreLocation"); //if (options.Location == MediaFileStoreLocation.Local) //{ //if (String.IsNullOrWhiteSpace (options.Directory)) // throw new ArgumentNullException ("options", "For local storage, options.Directory must be set"); if (Path.IsPathRooted(self.Directory)) { throw new ArgumentException("options.Directory must be a relative path", "options"); } //} }
private Task <MediaFile> TakeMediaAsync(string type, string action, StoreMediaOptions options) { int id = GetRequestId(); var ntcs = new TaskCompletionSource <MediaFile>(id); if (Interlocked.CompareExchange(ref completionSource, ntcs, null) != null) { throw new InvalidOperationException("Only one operation can be active at a time"); } context.StartActivity(CreateMediaIntent(id, type, action, options)); EventHandler <MediaPickedEventArgs> handler = null; handler = (s, e) => { TaskCompletionSource <MediaFile> tcs = Interlocked.Exchange(ref completionSource, null); MediaPickerActivity.MediaPicked -= handler; if (e.RequestId != id) { return; } if (e.Error != null) { tcs.SetException(e.Error); } else if (e.IsCanceled) { tcs.SetCanceled(); } else { tcs.SetResult(e.Media); } }; MediaPickerActivity.MediaPicked += handler; return(ntcs.Task); }
private void VerifyOptions (StoreMediaOptions options) { if (options == null) throw new ArgumentNullException ("options"); if (options.Directory != null && Path.IsPathRooted (options.Directory)) throw new ArgumentException ("options.Directory must be a relative path", "options"); }
private Task<MediaFile> TakeMediaAsync( string type, string action, StoreMediaOptions options ) { int id = GetRequestId(); var ntcs = new TaskCompletionSource<MediaFile>( id ); if(Interlocked.CompareExchange( ref completionSource, ntcs, null ) != null) { throw new InvalidOperationException( "Only one operation can be active at a time" ); } context.StartActivity( CreateMediaIntent( id, type, action, options ) ); EventHandler<MediaPickedEventArgs> handler = null; handler = ( s, e ) => { TaskCompletionSource<MediaFile> tcs = Interlocked.Exchange( ref completionSource, null ); MediaPickerActivity.MediaPicked -= handler; if(e.RequestId != id) { return; } if(e.Error != null) { tcs.SetException( e.Error ); } else if(e.IsCanceled) { tcs.SetCanceled(); } else { tcs.SetResult( e.Media ); } }; MediaPickerActivity.MediaPicked += handler; return ntcs.Task; }
private Intent CreateMediaIntent( int id, string type, string action, StoreMediaOptions options, bool tasked = true ) { Intent pickerIntent = new Intent( context, typeof(MediaPickerActivity) ); pickerIntent.PutExtra( MediaPickerActivity.ExtraId, id ); pickerIntent.PutExtra( MediaPickerActivity.ExtraType, type ); pickerIntent.PutExtra( MediaPickerActivity.ExtraAction, action ); pickerIntent.PutExtra( MediaPickerActivity.ExtraTasked, tasked ); if(options != null) { pickerIntent.PutExtra( MediaPickerActivity.ExtraPath, options.Directory ); pickerIntent.PutExtra( MediaStore.Images.ImageColumns.Title, options.Name ); var vidOptions = (options as StoreVideoOptions); if(vidOptions != null) { pickerIntent.PutExtra( MediaStore.ExtraDurationLimit, (int)vidOptions.DesiredLength.TotalSeconds ); pickerIntent.PutExtra( MediaStore.ExtraVideoQuality, (int)vidOptions.Quality ); } } return pickerIntent; }
private void VerifyOptions (StoreMediaOptions options) { if (options == null) throw new ArgumentNullException ("options"); //if (!Enum.IsDefined (typeof(MediaFileStoreLocation), options.Location)) // throw new ArgumentException ("options.Location is not a member of MediaFileStoreLocation"); //if (options.Location == MediaFileStoreLocation.Local) //{ if (options.Directory != null && Path.IsPathRooted (options.Directory)) throw new ArgumentException ("options.Directory must be a relative path", "options"); //} }