/// <summary>
        ///     Initializes a new instance of this class. 
        /// </summary>
        /// <param name="file">Music file to play.</param>
        public MusicPlayerWindow(string file)
        {
            InitializeComponent();

            _sound = AudioManager.LoadSound(file, 0);
            _soundChannel = _sound.Play();
            frequencyTrackBar.Value = _soundChannel.Frequency;
            panTrackBar.Value = (int)(_soundChannel.Pan * 50);
            volumeTrackBar.Value = (int)(_soundChannel.Volume);
            updateTimer.Start();
            fileLabel.Text = Path.GetFileName(file);
            Text = "Music Player - " + Path.GetFileName(file);
        }
Esempio n. 2
0
        /// <summary>
        ///		Loads an sound from a file or memory location.
        /// </summary>
        /// <param name="path">Memory location (or url) of sound file to load.</param>
        /// <param name="cache">If set to true this sound is added to the resource cache to save loading
        ///                     time when this sound is requested again.</param>
        /// <returns>The newly loaded sound.</returns>
        public static Sound LoadSound(object path, SoundFlags flags, bool cache)
        {
            if (ResourceManager.ResourceIsCached(path.ToString()) == true)
            {
                DebugLogger.WriteLog("Loading sound " + path.ToString() + " from cache.");
                return (Sound)ResourceManager.RetrieveResource(path.ToString());
            }

            DebugLogger.WriteLog("Loading sound from " + path.ToString() + ".");
            Sound sound = new Sound(path, flags);
            if (cache == true)
            {
                if ((flags & SoundFlags.Dynamic) != 0)
                    throw new Exception("Dynamic sounds cannot be cached.");
                ResourceManager.CacheResource(path.ToString(), sound);
            }
            return sound;
        }
 /// <summary>
 ///     Disposes of this class when it is closed.
 /// </summary>
 /// <param name="sender">Object that invoked this event.</param>
 /// <param name="e">Reason why this event was invoked.</param>
 private void MusicPlayerWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     _soundChannel.Stop();
     _soundChannel = null;
     _sound.Stop();
     _sound = null;
     GC.Collect();
 }
        /// <summary>
        ///     Reloads the currently selected sound.
        /// </summary>
        private void ReloadSound()
        {
            if (_soundChannel != null)
            {
                _soundChannel.Stop();
                _soundChannel = null;
            }
            if (_sound != null)
            {
                _sound.Stop();
                _sound = null;
            }
            GC.Collect();

            SoundFlags flags = 0;
            if (_streamed == true) flags |= SoundFlags.Streamed;
            if (_positional == true) flags |= SoundFlags.Positional;
            if (fileTreeView.SelectedNode != null && File.Exists(Engine.GlobalInstance.AudioPath + "/" + fileTreeView.SelectedNode.FullPath))
            {
                _sound = AudioManager.LoadSound(Engine.GlobalInstance.AudioPath + "/" + fileTreeView.SelectedNode.FullPath, flags);
                _soundChannel = _sound.Play();
            }
            SyncronizeWindow();
        }
Esempio n. 5
0
 public SoundScriptObject(Sound sound)
 {
     _nativeObject = sound;
 }