Пример #1
0
        } //END CallStopRecordingEvent

        //--------------------------------//
        public void SaveImageEvent( Texture tex )
        //--------------------------------//
        {
            if( tex != null )
            {
                //If our PersistentDataPath/ImageRecordings path does not exist, create it now
                if( !Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings") ) )
                {
                    Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings") );
                }

                string path = DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings/" + fileName + ".png" );

                if( UseGeneratedPath() )
                {
                    path = DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings/photo" + DateTime.Now.ToString( "dd-mm-yyyy-hh-mm-ss" ) + ".png" );
                }

                if( showDebug ) { Debug.Log( "BlockEventRecorder.cs SaveImageEvent() path = " + path ); }
                File.WriteAllBytes( path, ( tex as Texture2D ).EncodeToPNG() );

                //Add our image path to our list of saved images
                if( capturedPhotos == null ) { capturedPhotos = new List<string>(); }

                capturedPhotos.Add( path );

                //If there's an action to perform after saving this image, then do it
                if( onActionCompleted != null ) { onActionCompleted.Invoke(); }
            }

        } //END SaveImageEvent
Пример #2
0
        } //END SaveImageUsingUnityCameraEvent


        //--------------------------------//
        public void DeleteLocalStorageEvent()
        //--------------------------------//
        {

            //Delete all of the videos and photos at our persistent local storage
            if( Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath( "RecordedMedia" ) ) )
            {
                DeleteRecordedOrCapturedFiles( new DirectoryInfo( DatabaseStringHelper.CreatePersistentDataPath( "RecordedMedia" ) ) );
            }
            
            //Find all of the BlockEventRecorders in the scene and wipe their lists of saved photos and videos
            if( GameObject.FindObjectsOfType<BlockEventRecorder>() != null && GameObject.FindObjectsOfType<BlockEventRecorder>().Length > 1 )
            {
                List<BlockEventRecorder> recorders = GameObject.FindObjectsOfType<BlockEventRecorder>().ToList();

                foreach( BlockEventRecorder recorder in recorders )
                {
                    if( recorder != null )
                    {
                        recorder.ClearListsOfLocalStorageFiles();
                    }
                }
            }

            //There is only this BlockEventRecorder, wipe its lists
            else
            {
                ClearListsOfLocalStorageFiles();
            }

        } //END DeleteLocalStorageEvent
Пример #3
0
        } //END CallStartRecordingBlockEventExternalCamera

        //-------------------------------//
        private void OnRecordingComplete( string path )
        //-------------------------------//
        {
            //If our PersistentDataPath/VideoRecordings path does not exist, create it now
            if( !Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings") ) )
            {
                Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings") );
            }

            //Move the recording into the PersistentData folder under the 'VideoRecordings' subfolder
            if ( File.Exists( path ) )
            {
                FileInfo fileInfo = new FileInfo( path );

                if( fileInfo != null )
                {
                    File.Move( path, DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings/" + fileInfo.Name ) );
                    path = DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings/" + fileInfo.Name );
                }
            }

            if( showDebug ) { Debug.Log( "BlockEventRecorder.cs OnRecordingComplete() adding path to list of captured videos = " + path ); }

            //Add our path to our list of recorded videos
            if( recordedVideos == null ) { recordedVideos = new List<string>(); }

            recordedVideos.Add( path );

#if NATCORDER
            //If we were capturing images from a passed in camera, dispose of the cameraRecorder at this time to free up memory
            if( cameraRecorder != null )
            {
                cameraRecorder.Dispose();
                cameraRecorder = null;
            }
#endif

            //If we were capturing audio samples from an AudioListener or AudioSource, destroy the AudioGetter.cs helper script attached to it
            if( audioGetter != null )
            {
                Destroy( audioGetter );
                audioGetter = null;
            }

#if NATCORDER
            //If we were capturing audio from the app, dispose of the audioRecorder at this time
            if( audioRecorder != null )
            {
                audioRecorder.Dispose();
                audioRecorder = null;
            }
#endif

            if( onRecordingCompleted != null ) { onRecordingCompleted.Invoke( path ); }

        } //END OnRecordingComplete
Пример #4
0
        } //END OnSampleRecieved

        //------------------------------------------------//
        private void OnRecordToFileComplete( string path )
        //------------------------------------------------//
        {
            
            //If our PersistentDataPath/MicrophoneRecordings path does not exist, create it now
            if (!Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings") ))
            {
                Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings") );
            }

            //Move the recording into the PersistentData folder under the 'MicrophoneRecordings' subfolder
            if( File.Exists(path) )
            {
                FileInfo fileInfo = new FileInfo(path);

                if (fileInfo != null)
                {
                    string name = fileInfo.Name;

                    if( IsFileNameAutomaticallyGenerated() )
                    {
                        name = DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss") + ".wav";
                    }
                    else if( IsFileNameCustom() && customFileName != "" )
                    {
                        name = customFileName + ".wav";
                    }

                    File.Move(path, DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings/" + name));
                    path = DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings/" + name);
                }
            }

            //Store the final path of the audio file for reference
            if ( audioRecordingsInLocalStorage == null ) { audioRecordingsInLocalStorage = new List<string>(); }

            audioRecordingsInLocalStorage.Add( path );

            //Let other system know that the recording has completed
            if( onRecordToFileComplete != null) { onRecordToFileComplete.Invoke( path ); }

        } //END OnRecordToFileComplete
        } //END Start



        //---------------------------------------------//
        public IEnumerator CopyVideoToPersistentDataPath( string urlWithPath )
        //---------------------------------------------//
        {

            string fileName = DatabaseStringHelper.GetFileNameWithExtension( urlWithPath );
            string persistentPath = DatabaseStringHelper.CreatePersistentDataPath( fileName );

            string streamingPath = urlWithPath;
            if( urlWithPath.Contains( "StreamingAssets" ) ) { streamingPath = DatabaseStringHelper.CreateStreamingAssetsPath( urlWithPath.Replace( "StreamingAssets/", "" ), DatabaseStringHelper.StringStyle.WithEscapeUriAndSystemPathCombine ); }


            if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) ... filename = " + fileName + ", persistentPath = " + persistentPath + ", streamingPath = " + streamingPath );


            //If the video does not exist in the persistent data path folder, we need to copy all of it's bytes over
            if( !File.Exists( persistentPath ) )
            {
                WWW www = new WWW( streamingPath );

                while( !www.isDone ) { yield return new WaitForSeconds( .1f ); }

                if( string.IsNullOrEmpty( www.error ) )
                {
                    if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) we found the video in StreamingAssetsPath = " + streamingPath );

                    if( www.bytes != null && www.bytes.Length > 0 )
                    {
                        if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) we found the www.bytes = " + www.bytes.Length.ToString() );


                        //We found the video, copy it's data over over time (not all at once to prevent a crash)
                        Stream stream = new MemoryStream( www.bytes );

                        using( FileStream output = new FileStream( persistentPath, FileMode.Create, FileAccess.Write ) )
                        {
                            byte[] buffer = new byte[ 32 * 1024 ]; //a 32KB-sized buffer is the most efficient
                            int bytesRead;

                            while( ( bytesRead = stream.Read( buffer, 0, buffer.Length ) ) > 0 )
                            {
                                output.Write( buffer, 0, bytesRead );
                            }

                            output.Flush();
                        }

                        //We found the video, copy it's data over
                        //File.WriteAllBytes( persistentPath, www.bytes );

                    }
                    else
                    {
                        if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) we couldn't find any www.bytes = " + www.bytes.Length.ToString() );
                    }
                }
                else
                {
                    if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) Getting the video from StreamingAssets had an error = " + www.error + ", streamingAssetsPath = " + streamingPath );
                }

                www.Dispose();
                www = null;
            }
            else
            {
                if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) the video already exists" );
            }

        } //END CopyVideoToPersistentDataPath