public override async void FinishedRecording(AVCaptureFileOutput captureOutput, NSUrl outputFileUrl, NSObject[] connections, NSError error)
        {
            if (UIVideo.IsCompatibleWithSavedPhotosAlbum(outputFileUrl.Path))
            {
                var library = new ALAssetsLibrary();
                library.WriteVideoToSavedPhotosAlbum(outputFileUrl, async(path, e2) =>
                {
                    if (e2 != null)
                    {
                        new UIAlertView("", e2.ToString(), null, "Error Occurred", null).Show();
                    }
                    else
                    {
                        view.activityIndicator.StopAnimating();
                        new UIAlertView("", "Saved to Photos", null, "Ok", null).Show();

                        //by using messaging center we can send data to portable CameraPage
                        NSData data      = NSData.FromUrl(outputFileUrl);
                        byte[] dataBytes = new byte[data.Length];
                        System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));
                        MessagingCenter.Send <string, byte[]>("VideoByteArrayReady", "ByteArrayIsReady", dataBytes);
                        MessagingCenter.Send <string, string>("VideoPathReady", "VideoPathReady", outputFileUrl.AbsoluteString);

                        await(element as CameraPage).Navigation.PopAsync();
                    }
                });
            }
            else
            {
                new UIAlertView("Incompatible", "Incompatible", null, "Ok", null).Show();
            }
        }
示例#2
0
        public void SaveFileToPhotosAlbum(string filePath, byte[] fileData)
        {
            string ext = Path.GetExtension(filePath);

            if (ext.ToUpper() == ".MOV" || ext.ToUpper() == ".M4V")
            {
                File.WriteAllBytes(filePath, fileData);
                if (UIVideo.IsCompatibleWithSavedPhotosAlbum(filePath))
                {
                    UIVideo.SaveToPhotosAlbum(filePath, (path, error) => {
                        if (error == null)
                        {
                            if (FileSavedToPhotosAlbum != null)
                            {
                                FileSavedToPhotosAlbum(this, new FilesSavedToPhotosAlbumArgs(path, path));
                            }
                        }
                        else
                        {
                            Console.Out.WriteLine("Video {0} cannot be saved to photos album!", filePath);
                        }
                    });
                }
            }
            else if (ext.ToUpper() == ".JPEG" || ext.ToUpper() == ".JPG" || ext.ToUpper() == ".PNG")
            {
                NSData imgData = NSData.FromArray(fileData);
                var    img     = UIImage.LoadFromData(imgData);
                var    meta    = new NSDictionary();

                ALAssetsLibrary library = new ALAssetsLibrary();
                library.WriteImageToSavedPhotosAlbum(img.CGImage,
                                                     meta,
                                                     (assetUrl, error) => {
                    if (error == null)
                    {
                        if (FileSavedToPhotosAlbum != null)
                        {
                            FileSavedToPhotosAlbum(this, new FilesSavedToPhotosAlbumArgs(assetUrl.ToString(), filePath));
                        }
                        else
                        {
                            Console.Out.WriteLine("Image {0} cannot be saved to photos album!", filePath);
                        }
                    }
                });
                img.Dispose();
            }
            else
            {
                File.WriteAllBytes(filePath, fileData);
                if (FileSavedToPhotosAlbum != null)
                {
                    FileSavedToPhotosAlbum(this, new FilesSavedToPhotosAlbumArgs(filePath, filePath));
                }
            }
        }
 private void Start()
 {
     tutorialCanvas = GameObject.Find("TutorialCanvas").GetComponent <Canvas>();
     if (tutorialCanvas != null)
     {
         infoText    = tutorialCanvas.FindComponent <Text>("Info");
         videoPlayer = tutorialCanvas.FindComponent <VideoPlayer>("TutorialVideo");
         updater     = videoPlayer.GetComponent <UIVideo>();
         readyText   = tutorialCanvas.FindComponent <Text>("ReadyText");
         StartCoroutine(Slideshow());
     }
 }
示例#4
0
        private static void CreateUIVideo()
        {
            VideoClip clip   = AssetDatabase.LoadAssetAtPath <VideoClip>("Assets/Bundles/Videos/4.mp4");
            int       width  = 256;
            int       height = 256;

            if (clip != null)
            {
                width  = (int)clip.width;
                height = (int)clip.height;
            }

            GameObject child = CreateUIRectTransform(width, height);

            if (child == null)
            {
                return;
            }

            UIVideo video = child.AddComponent <UIVideo>();

            child.name  = video.GetType().Name;
            child.layer = 5;

            video.raycastTarget = true;
            video.type          = Image.Type.Simple;

            var videoPlayer = video.GetComponent <VideoPlayer>();

            videoPlayer.renderMode = VideoRenderMode.RenderTexture;
            videoPlayer.controlledAudioTrackCount = 1;
            videoPlayer.audioOutputMode           = VideoAudioOutputMode.AudioSource;
            videoPlayer.source = VideoSource.VideoClip;
            videoPlayer.clip   = clip;

            var audioSrc = video.GetComponent <AudioSource>();

            videoPlayer.EnableAudioTrack(0, true);
            videoPlayer.SetTargetAudioSource(0, audioSrc);

            Material mat = new Material(Shader.Find("Unlit/Texture"));

            video.material = mat;

            RenderTexture texture = new RenderTexture(width, height, 32);

            texture.name              = "Video Render Texture";
            texture.dimension         = TextureDimension.Tex2D;
            texture.format            = RenderTextureFormat.ARGB32;
            mat.mainTexture           = texture;
            videoPlayer.targetTexture = texture;
        }
        public static bool SaveVideoToGalery(NSUrl video, string path, string albumName)
        {
            var saved       = true;
            var compatible  = UIVideo.IsCompatibleWithSavedPhotosAlbum(path);
            var customAlbum = string.IsNullOrEmpty(albumName) ? null : FindOrCreateAlbum(albumName);

            if (!compatible)
            {
                return(false);
            }
            UIVideo.SaveToPhotosAlbum(path, (path, error) =>
            {
                if (error != null)
                {
                    saved = false;
                    Console.WriteLine(error);
                }
                else if (customAlbum != null)
                {
                    var savedAsset = (PHAsset)PHAsset.FetchAssets(PHAssetMediaType.Video,
                                                                  new PHFetchOptions
                    {
                        SortDescriptors = new[] { new NSSortDescriptor("creationDate", false) },
                        FetchLimit      = 1
                    }).FirstOrDefault();
                    if (savedAsset != null)
                    {
                        PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
                        {
                            var albumRequest = PHAssetCollectionChangeRequest.ChangeRequest(customAlbum);
                            albumRequest?.AddAssets(new[] { savedAsset });
                        },
                                                                         (success, error) =>
                        {
                            if (!success)
                            {
                                Console.WriteLine(error);
                                saved = success;
                            }
                        }
                                                                         );
                    }
                }
            });

            return(saved);
        }