Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="self"></param>
        /// <param name="rootPath"></param>
        /// <returns></returns>
        public 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));
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="self"></param>
        /// <param name="rootPath"></param>
        /// <param name="checkExists"></param>
        /// <returns></returns>
        public 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));
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="self"></param>
 public 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 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<Media.Plugin.Abstractions.MediaFile> TakeMediaAsync(string type, string action, StoreMediaOptions options)
		{
			int id = GetRequestId();

      var ntcs = new TaskCompletionSource<Media.Plugin.Abstractions.MediaFile>(id);
			if (Interlocked.CompareExchange (ref this.completionSource, ntcs, null) != null)
				throw new InvalidOperationException ("Only one operation can be active at a time");

			this.context.StartActivity (CreateMediaIntent (id, type, action, options));

			EventHandler<MediaPickedEventArgs> handler = null;
			handler = (s, e) =>
			{
        var tcs = Interlocked.Exchange(ref this.completionSource, null);

				MediaPickerActivity.MediaPicked -= handler;

				if (e.RequestId != id)
					return;

        if (e.Error != null)
          tcs.SetResult(null);
        else if (e.IsCanceled)
          tcs.SetResult(null);
        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 (this.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);
				}
			}
      //pickerIntent.SetFlags(ActivityFlags.ClearTop);
      pickerIntent.SetFlags(ActivityFlags.NewTask);
			return pickerIntent;
		}