GAudio.AGATAudioFile.OpenAudioFileAtPath C# (CSharp) Méthode

OpenAudioFileAtPath() public static méthode

Creates and returns a ready to use AGATAudioFile object. Wrap in a try catch block if you are not sure that the file type is supported.
public static OpenAudioFileAtPath ( string path ) : AGATAudioFile
path string
Résultat AGATAudioFile
        public static AGATAudioFile OpenAudioFileAtPath( string path )
        {
            string ext = Path.GetExtension( path ).ToLower();

            if( ext != ".wav" && ext != ".ogg" )
            {
                throw new GATException( "Unrecognized extension: " + ext );
            }

            if( !File.Exists( path ) )
            {
                throw new GATException( "No such file!" );
            }

            if( ext == ".wav" )
                return new WavFile( path );

            #if GAT_NO_THREADING
            throw new GATException("NVorbis ogg decoder not compatible with GAT_NO_THREADING flag" );
            #else

            FileStream stream = File.OpenRead( path );

            return new OggFile( stream );
            #endif
        }

Usage Example

Exemple #1
0
        void LoadSampleFromStreamingAssets(GATDataAllocationMode mode, GATSampleInfo info, Dictionary <string, GATData> loadedSamples)
        {
            AGATAudioFile file;
            string        path;

            GATData[] loadedChannels;
            int       i;

            path = info.GetStreamingAssetFullPath();

            using (file = AGATAudioFile.OpenAudioFileAtPath(path))
            {
                loadedChannels = GATAudioLoader.SharedInstance.LoadSync(file, mode);
            }

            if (loadedChannels.Length == 1)
            {
                loadedSamples.Add(info.Name, loadedChannels[0]);
                return;
            }

            for (i = 0; i < loadedChannels.Length; i++)
            {
                loadedSamples.Add(string.Format("{0}_{1}", info.Name, i), loadedChannels[i]);
            }
        }
All Usage Examples Of GAudio.AGATAudioFile::OpenAudioFileAtPath