StartImport() public method

public StartImport ( string mPath ) : AudioClip
mPath string
return UnityEngine.AudioClip
Exemplo n.º 1
0
    private void Play()
    {
        if (File.Exists(Settings.Selected.File.Path))
        {
            // Set active file
            Settings.Active.File = Settings.Selected.File;

            // Reset selected file
            Settings.Selected.File = null;

            // Get active file
            FileObj file = Settings.Active.File;

            if (file != null)
            {
                // Play file
                if (Path.GetExtension(file.Path) == ".mp3")
                {
                    clip = MP3Import.StartImport(file.Path);
                    StartPlay();
                }
                else
                {
                    // Get audio resource
                    WWW resource = new WWW("file:///" + file.Path.Replace('\\', '/').TrimStart(new char [] { '/' }));
                    clip = resource.GetAudioClip(true, false);

                    // Wait until file is loaded
                    while (clip.loadState != AudioDataLoadState.Loaded)
                    {
                        if (clip.loadState == AudioDataLoadState.Failed)
                        {
                            Next();
                            return;
                        }
                    }

                    if (clip != null && clip.length > 0)
                    {
                        StartPlay();
                    }
                    else
                    {
                        Next();
                    }
                }
            }
        }
        else
        {
            // Try to play next file
            Next();
        }
    }
Exemplo n.º 2
0
 private static AudioClip LoadMp3Clip(string filePath)
 {
     try
     {
         Utils.Log("Loading MP3 clip");
         MP3Import importer = new MP3Import();
         AudioClip clip     = importer.StartImport(filePath);
         clip.name = Path.GetFileNameWithoutExtension(filePath);
         return(clip);
     }
     catch (Exception ex)
     {
         // TODO: Don't continually attempt to load failing tracks when they're the only one in the playlist.
         Debug.LogError("[STED] Error loading MP3 " + filePath + ": " + ex.Message + "\r\n" + ex.StackTrace);
         return(null);
     }
 }
    protected void FileSelectedCallback(string path, string directory)
    {
        m_fileBrowser = null;

        // handle mp3 file
        if( mostRecentExtension == "mp3")
        {
            lastUsedDirectorymp3 = directory;
            filePathmp3 = path;

             if(filePathmp3 != null)
            {
                mp3Importer = (MP3Import)GetComponent("MP3Import");
                mp3Importer.StartImport(filePathmp3);

                audioDirector.audioSourceArray[0].Stop();
                audioDirector.audioSourceArray[0] = null;

                audioDirector.audioSourceArray[0] = mp3Importer.audioSource;
                audioDirector.audioSourceArray[0].Play();
                audioDirector.currentlyPlayingFileName = Path.GetFileName(path);

                // fix for low pass filter not working on loaded songs
                audioListener.enabled = false;
                audioListener.enabled = true;

                // fixes memory leaked cause by unsed audio clips (occurs when loading new songs)
                Resources.UnloadUnusedAssets();

            }
        } // handle parameters file
        else if( mostRecentExtension == "txt")
        {
            lastUsedDirectorytxt = directory;
            filePathtxt = path;

            // load parameters text file into string
            string rawFileString = File.ReadAllText(filePathtxt);
            string[] rawSplit = rawFileString.Split('|');
            string amplitudeListString = rawSplit[1];
            string frequencyStartString = rawSplit[2];
            string frequencyListString = rawSplit[3];
            string rgbColorScaleFactorsString = rawSplit[4];

            // copy over amplitudes
            for(int i = 0; i < audioDirector.scalingPerDecadeArray.Length; i++)
                audioDirector.scalingPerDecadeArray[i] = float.Parse( amplitudeListString.Split(',')[i] );

         		// copy over frequency start index
         		audioDirector.sampleStartIndex = int.Parse( frequencyStartString.Trim() );

         		// copy over frequency distribution
         		for(int i = 0; i < audioDirector.samplesPerDecadeArray.Length; i++)
         			audioDirector.samplesPerDecadeArray[i] = int.Parse( frequencyListString.Split(',')[i] );

         		// copy over rgb scale values
         		audioDirector.rScale = float.Parse( rgbColorScaleFactorsString.Split(',')[0] );
         		audioDirector.gScale = float.Parse( rgbColorScaleFactorsString.Split(',')[1] );
         		audioDirector.bScale = float.Parse( rgbColorScaleFactorsString.Split(',')[2] );

        }

        //isActive = false;
    }
Exemplo n.º 4
0
 public void importAudio()
 {
     mp3.StartImport();
 }
Exemplo n.º 5
0
 private static AudioClip LoadMp3Clip(string filePath)
 {
     try
     {
         Utils.Log("Loading MP3 clip");
         MP3Import importer = new MP3Import();
         AudioClip clip = importer.StartImport(filePath);
         clip.name = Path.GetFileNameWithoutExtension(filePath);
         return clip;
     }
     catch (Exception ex)
     {
         // TODO: Don't continually attempt to load failing tracks when they're the only one in the playlist.
         Debug.LogError("[STED] Error loading MP3 " + filePath + ": " + ex.Message + "\r\n" + ex.StackTrace);
         return null;
     }
 }
        /// <summary>
        /// Adds any MP3s in the SoundtrackEditory\Music\ directory to the GameDatabase.
        /// </summary>
        /// <remarks>
        /// Unity no longer supports loading MP3 tracks, giving the error:
        ///    "Streaming of 'mp3' on this platform is not supported"
        /// Instead, this is achieved using the MPG123 utility to load the MP3 
        /// data unto a Unity AudioClip. For details, see here:
        /// http://answers.unity3d.com/questions/380838/is-there-any-converter-mp3-to-ogg-.html
        /// </remarks>
        private void LoadMp3s()
        {
            try
            {
                // Check all files in the Music directory; find the mp3s.
                Debug.Log("STED: Running MP3 importer...");
                DirectoryInfo modDir = Directory.GetParent(AssemblyDirectory);
                string path = Path.Combine(modDir.FullName, "Music") + Path.DirectorySeparatorChar;
                foreach (string file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
                {
                    string ext = Path.GetExtension(file);
                    if (!String.IsNullOrEmpty(ext) && ext.Equals(".mp3", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MP3Import importer = new MP3Import();
                        AudioClip clip = importer.StartImport(file);

                        // Set the clip name to match the format used for clips in the GameDatabase.
                        string clipShortPath = Path.GetFileName(modDir.FullName) +
                            file.Substring(modDir.FullName.Length, file.Length - modDir.FullName.Length - ".mp3".Length);
                        if (Path.DirectorySeparatorChar == '\\') // Change Windows path separators to match the GameDatabase.
                            clipShortPath = clipShortPath.Replace('\\', '/');

                        clip.name = clipShortPath;
                        GameDatabase.Instance.databaseAudio.Add(clip);
                    }
                }
                Debug.Log("STED: Finished importing MP3s.");
            }
            catch (Exception ex)
            {
                Debug.LogError("STED MP3 Import error: " + ex.Message);
            }
        }