Ejemplo n.º 1
0
    /// <summary>
    /// Take a video with specified options
    /// </summary>
    /// <param name="options">Video Media Options</param>
    /// <returns>Media file of new video or null if canceled</returns>
    public Task<MediaFile> TakeVideoAsync(StoreVideoOptions options)
    {
      if (!IsTakeVideoSupported)
        throw new NotSupportedException();
      if (!IsCameraAvailable)
        throw new NotSupportedException();

      VerifyCameraOptions(options);

      return GetMediaAsync(UIImagePickerControllerSourceType.Camera, TypeMovie, options);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Take a video with specified options
 /// </summary>
 /// <param name="options">Video Media Options</param>
 /// <returns>Media file of new video or null if canceled</returns>
 public Task<MediaFile> TakeVideoAsync(StoreVideoOptions options)
 {
   throw new NotSupportedException();
 }
Ejemplo n.º 3
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="options"></param>
    /// <returns></returns>
    public MediaPickerController GetTakeVideoUI(StoreVideoOptions options)
    {
      if (!IsTakeVideoSupported)
        throw new NotSupportedException();
      if (!IsCameraAvailable)
        throw new NotSupportedException();

      VerifyCameraOptions(options);

      var d = new MediaPickerDelegate(null, UIImagePickerControllerSourceType.Camera, options);
      return SetupController(d, UIImagePickerControllerSourceType.Camera, TypeMovie, options);
    }
Ejemplo n.º 4
0
 public Task<MediaFile> TakeVideoAsync(StoreVideoOptions options)
 {
     return _media.TakeVideoAsync(options);
 }
        async void OnVideoButtonClicked(object sender, EventArgs e)
        {
            try
            {


                IProgressBar progres = DependencyService.Get<IProgressBar>();
                if (Device.OS != TargetPlatform.iOS)
                    progres.ShowProgressbar("Preparing media..");
                if ((sender as CustomImageButton).ClassId == "camera")
                {
                    try
                    {
                        if (Device.OS == TargetPlatform.WinPhone)
                        {
                            PurposeColor.interfaces.ICameraCapture camera = DependencyService.Get<PurposeColor.interfaces.ICameraCapture>();
                            camera.RecodeVideo();
                        }
                        else if (Media.Plugin.CrossMedia.Current.IsCameraAvailable)
                        {
                            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported)
                            {
                                progres.HideProgressbar();
                                return;
                            }



							string fileName = string.Format("Video{0}.mp4", System.DateTime.Now.ToString("yyyyMMddHHmmss"));
							StoreVideoOptions videoOptions = new StoreVideoOptions();
							videoOptions.Name = fileName;
							videoOptions.Directory = "DefaultVideos";
							videoOptions.DesiredLength = TimeSpan.FromMinutes(5);
							videoOptions.Quality = VideoQuality.Low;

							if( Device.OS == TargetPlatform.Android )
							{
								IVideoCompressor compress = DependencyService.Get<IVideoCompressor>();
								Size camSize =  compress.GetCameraSize();
								if( camSize.Width > 5000 )
									videoOptions.Quality = VideoQuality.Low;
								else
									videoOptions.Quality = VideoQuality.Medium;
							}

							var file = await CrossMedia.Current.TakeVideoAsync( videoOptions );

						//	MasterObject.ShowAlert( "test", null );

							await Task.Delay( TimeSpan.FromSeconds( 2 ) );


							//progres.ShowProgressbar( "video is compressing..." );

                            if (file == null)
                            {
                                progres.HideProgressbar();
                                return;
                            }

							string videoFilename = Path.GetFileName( file.Path );
							MemoryStream ms = new MemoryStream();
							/*file.GetStream().CopyTo(ms);*/

							if( Device.OS == TargetPlatform.Android )
							{
								IVideoCompressor compressor = DependencyService.Get<IVideoCompressor>();
								ms = compressor.CompressVideo( file.Path, App.DownloadsPath + videoFilename, false );
								ms.Position = 0;
							}
							else if( Device.OS == TargetPlatform.iOS )
							{
								file.GetStream().CopyTo(ms);
							}
	

			
							if( ms == null )
							{
								MasterObject.DisplayAlert("Error in adding video.");
								return;
							}
                            if (ms.Length > 15728640)
                            {
                                MasterObject.DisplayAlert("Can not add video, Maximum file size limied to 15 MB");
                                progres.HideProgressbar();
                                ms = null;
                                file = null;
                                GC.Collect();
                                return;
                            }



							if( Device.OS == TargetPlatform.Android )
							{
								MasterObject.AddFileToMediaArray(ms, App.DownloadsPath + videoFilename, PurposeColor.Constants.MediaType.Video);
							}
							else if( Device.OS == TargetPlatform.iOS )
							{
								MasterObject.AddFileToMediaArray(ms, file.Path, PurposeColor.Constants.MediaType.Video);
							}

                        }

                    }
                    catch (Exception ex)
                    {
                        var test = ex.Message;
                    }
                    progres.HideProgressbar();
                }
                else if ((sender as CustomImageButton).ClassId == "gallery")
                {
                    try
                    {
                        if (Device.OS == TargetPlatform.WinPhone)
                        {
                            //https://social.msdn.microsoft.com/Forums/windowsapps/en-US/7e4492dc-d8f3-4dc5-8055-625352aaa8b6/fileopenpicker-class-on-wp8
                            // We do not currently support choosing files other than photos or choosing files from other Store apps

                            // list the video folder content in a list view.
                            // http://www.c-sharpcorner.com/UploadFile/2b876a/how-to-use-folders-and-files-in-windows-phone-8/

                            PurposeColor.interfaces.IFileBrowser fileBrowser = DependencyService.Get<PurposeColor.interfaces.IFileBrowser>();
                            List<String> files = await fileBrowser.GetVideoFileList();
                            //fileBrowser = null; // so the the memory can be released.

                            if (files == null || files.Count < 1)
                            {
                                //progres.HideProgressbar();
                                // should hide the DataTemplateSelector so don't return from here.'
                                MasterObject.DisplayAlert("Video files not accessible");
                            }
                            else
                            {
                                // display the file names in custom picker, and get the file once the user taps on any of the file name.
                                View fileView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "filePicker");
                                if (fileView != null)
                                {
                                    PageContainer.Children.Remove(fileView);
                                    fileView = null;
                                }

                                List<CustomListViewItem> customList = new List<CustomListViewItem>();
                                foreach (var item in files)
                                {
                                    customList.Add(new CustomListViewItem { Name = item });
                                }

                                CustomPicker filePicker = new CustomPicker(PageContainer, customList, 65, "Select file", true, false);
                                //customList = null;
                                filePicker.WidthRequest = App.screenWidth;
                                filePicker.HeightRequest = App.screenHeight;
                                filePicker.ClassId = "filePicker";
                                PageContainer.AddChildToLayout(filePicker, 0, 0);

                                filePicker.listView.ItemSelected += async (s, eve) =>
                                {
                                    CustomListViewItem item = eve.SelectedItem as CustomListViewItem;
                                    MemoryStream videoFileMS = await fileBrowser.GetVideostream(item.Name);

                                    if (videoFileMS != null)
                                    {
                                        MasterObject.AddFileToMediaArray(videoFileMS, item.Name, Constants.MediaType.Video);
                                    }
                                    else
                                    {
                                        MasterObject.DisplayAlert("File read error");
                                    }

                                    View filepickView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "filePicker");
                                    if (filepickView != null)
                                    {
                                        PageContainer.Children.Remove(filepickView);
                                        fileView = null;
                                    }
                                    //videoFileMS = null;
                                };

                                //fileBrowser = null;
                            }
                        }
                        else if (CrossMedia.Current.IsPickVideoSupported)
                        {
							var file = await CrossMedia.Current.PickVideoAsync();

                            if (file == null)
                            {
                                progres.HideProgressbar();
                                return;
                            }

                            MemoryStream ms = new MemoryStream();
                           /* file.GetStream().CopyTo(ms);
                            ms.Position = 0;*/

							if( Device.OS == TargetPlatform.Android )
							{
								string videoFilename = Path.GetFileName( file.Path );
								IVideoCompressor compressor = DependencyService.Get<IVideoCompressor>();
								ms = compressor.CompressVideo( file.Path, App.DownloadsPath + videoFilename, false );
								ms.Position = 0;
							}
							else if( Device.OS == TargetPlatform.iOS )
							{
								string videoFilename = Path.GetFileName( file.Path );
								IVideoCompressor compressor = DependencyService.Get<IVideoCompressor>();
								ms = compressor.CompressVideo( file.Path, App.DownloadsPath + videoFilename, false );
							}


                            if (ms.Length > 15728640)
                            {
                                MasterObject.DisplayAlert("Can not add video, Maximum file size limied to 15 MB");
                                progres.HideProgressbar();
                                ms = null;
                                file = null;
                                GC.Collect();
                                return;
                            }

							if( Device.OS == TargetPlatform.Android )
							{
								MasterObject.AddFileToMediaArray(ms, file.Path, PurposeColor.Constants.MediaType.Video);	
							}
							else if( Device.OS == TargetPlatform.iOS )
							{
								string fileName = Path.GetFileNameWithoutExtension( file.Path ) + ".mp4";
								string downloadFilePath = Path.Combine(App.DownloadsPath, fileName );
								MasterObject.AddFileToMediaArray(ms, downloadFilePath, PurposeColor.Constants.MediaType.Video);
							}

                            
                        }
                        else
                        {
                            progres.HideProgressbar();
                            MasterObject.DisplayAlert("Video library not available");
                            return;
                        }


                    }
                    catch (Exception ex)
                    {
                        var test = ex.Message;
                    }
                    progres.HideProgressbar();
                }

                View pickView = PageContainer.Children.FirstOrDefault(pick => pick.ClassId == "mediachooser");
                PageContainer.Children.Remove(pickView);
                pickView = null;
                progres.HideProgressbar();

                GC.Collect();

            }
            catch (Exception ex)
            {
                var test = ex.Message;
            }
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Take a video with specified options
    /// </summary>
    /// <param name="options">Video Media Options</param>
    /// <returns>Media file of new video or null if canceled</returns>
    public Task<Media.Plugin.Abstractions.MediaFile> TakeVideoAsync(StoreVideoOptions options)
		{
			if (!IsCameraAvailable)
				throw new NotSupportedException();

			VerifyOptions (options);

			return TakeMediaAsync ("video/*", MediaStore.ActionVideoCapture, options);
		}
Ejemplo n.º 7
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="options"></param>
    /// <returns></returns>
		public Intent GetTakeVideoUI (StoreVideoOptions options)
		{
			if (!IsCameraAvailable)
				throw new NotSupportedException();

			VerifyOptions (options);

			return CreateMediaIntent (GetRequestId(), "video/*", MediaStore.ActionVideoCapture, options, tasked: false);
		}