示例#1
0
        /// <summary>
        /// Play a .mp3 or .wav audio file
        /// </summary>
        /// <param name="filePath">The relative path to the audio file</param>
        /// <param name="loop">Determine if the sound should loop</param>
        public static void PlayAudio(string filePath, bool loop) // testa isto  <- pelos scripts
        {
            if (!initialized)
            {
                return;
            }

            // Add the project path
            filePath = SceneManager.GameProject.ProjectPath + "//" + filePath;

#if WINDOWS
            WaveChannel32 stream = CreateInputStream(filePath, 1, false);

            if (stream != null)
            {
                mainOutputStream = new LoopStream(stream);
                mainOutputStream.EnableLooping = loop;

                try
                {
                    waveOutDevice.Init(mainOutputStream);
                }
                catch (Exception initException)
                {
                    Console.WriteLine(String.Format("{0}", initException.Message), "Error Initializing Output");
                    return;
                }

                waveOutDevice.Play();
            }
#endif
        }
示例#2
0
        /// <summary>
        /// Plays the selected audio file
        /// </summary>
        public void Play()
        {
            if (this.Disabled)
            {
                return;
            }

            string _filePath = SceneManager.GameProject.ProjectPath + "//" + filePath;

            if (SceneManager.IsEditor)
            {
                return;
            }

#if WINDOWS
            if (_filePath != lastLoadedPath || waveOutDevice == null)
            {
                if (!File.Exists(filePath))
                {
                    return;
                }

                WaveChannel32 stream = Audio.CreateInputStream(_filePath, volume, false);

                if (stream != null)
                {
                    mainOutputStream = new LoopStream(stream);
                    mainOutputStream.EnableLooping = loop;

                    try
                    {
                        waveOutDevice.Init(mainOutputStream);
                    }
                    catch (Exception initException)
                    {
                        Console.WriteLine(String.Format("{0}", initException.Message), "Error Initializing Output");
                        return;
                    }

                    waveOutDevice.Play();

                    lastLoadedPath = _filePath;
                }
            }
            else
            {
                waveOutDevice.Play();
            }
#endif
        }
示例#3
0
        /// <summary>
        /// Plays the selected audio file
        /// </summary>
        public void Play()
        {
            if (this.Disabled) return;

            string _filePath = SceneManager.GameProject.ProjectPath + "//" + filePath;

            if (SceneManager.IsEditor) return;

#if WINDOWS
            if (_filePath != lastLoadedPath || waveOutDevice == null)
            {

                if (!File.Exists(filePath)) return;

                WaveChannel32 stream = Audio.CreateInputStream(_filePath, volume, false);

                if (stream != null)
                {
                    mainOutputStream = new LoopStream(stream);
                    mainOutputStream.EnableLooping = loop;

                    try
                    {
                        waveOutDevice.Init(mainOutputStream);
                    }
                    catch (Exception initException)
                    {
                        Console.WriteLine(String.Format("{0}", initException.Message), "Error Initializing Output");
                        return;
                    }

                    waveOutDevice.Play();

                    lastLoadedPath = _filePath;
                }
            }
            else
            {
                waveOutDevice.Play();
            }
#endif
        }
示例#4
0
        /// <summary>
        /// Play a .mp3 or .wav audio file
        /// </summary>
        /// <param name="filePath">The relative path to the audio file</param>
        /// <param name="loop">Determine if the sound should loop</param>
        public static void PlayAudio(string filePath, bool loop) // testa isto  <- pelos scripts
        {
            if (!initialized) return;

            // Add the project path
            filePath = SceneManager.GameProject.ProjectPath + "//" + filePath;

#if WINDOWS
            WaveChannel32 stream = CreateInputStream(filePath, 1, false);
            
            if (stream != null)
            {
                mainOutputStream = new LoopStream(stream);
                mainOutputStream.EnableLooping = loop;

                try
                {
                    waveOutDevice.Init(mainOutputStream);
                }
                catch (Exception initException)
                {
                    Console.WriteLine(String.Format("{0}", initException.Message), "Error Initializing Output");
                    return;
                }

                waveOutDevice.Play();
            }
#endif
        }