Exemple #1
0
 public void StopMusic()
 {
     if (m_MusicCurrentlyPlaying != null)
     {
         m_MusicCurrentlyPlaying.Stop();
         m_MusicCurrentlyPlaying.Dispose();
         m_MusicCurrentlyPlaying = null;
     }
 }
        public void PlayMusic(int id)
        {
            if (id < 0) // not a valid id, used to stop music.
            {
                StopMusic();
                return;
            }

            if (!m_Music.ContainsKey(id))
            {
                string name;
                bool loops;
                if (UltimaXNA.Ultima.IO.MusicData.TryGetMusicData(id, out name, out loops))
                {
                    m_Music.Add(id, new UOMusic(id, name, loops));
                }
                else
                {
                    Tracer.Error("Received unknown music id {0}", id);
                    return;
                }
            }

            UOMusic toPlay = m_Music[id];

            if (toPlay != m_MusicCurrentlyPlaying)
            {
                // stop the current song
                StopMusic();

                m_MusicCurrentlyPlaying = null;
                // if (m_MusicCurrentlyPlaying.Status != SoundState.Loaded)
                //    m_MusicCurrentlyPlaying.Load(); // this should really be threaded

                // open resource
                string mciCommand = string.Format("open \"{0}\" type MPEGVideo alias {1}", toPlay.Path, c_InternalMusicName);
                int result = SendMediaPlayerCommand(mciCommand, null, 0, IntPtr.Zero);
                if (result == 0)
                {
                    m_MusicCurrentlyPlaying = toPlay;
                    // start playing
                    string playCommand = string.Format("play {0} from 0", c_InternalMusicName);
                    if (m_MusicCurrentlyPlaying.DoLoop)
                    {
                        playCommand += " repeat";
                    }
                    if (SendMediaPlayerCommand(playCommand, null, 0, IntPtr.Zero) != 0)
                    {
                        Tracer.Error("Error playing mp3 file {0}", toPlay.Path);
                    }
                }
                else
                {
                    Tracer.Error("Error opening mp3 file {0}", toPlay.Path);
                }
            }
        }
Exemple #3
0
        public void PlayMusic(int id)
        {
            if (Settings.Audio.MusicOn)
            {
                if (id < 0) // not a valid id, used to stop music.
                {
                    StopMusic();
                    return;
                }

                if (!m_Music.ContainsKey(id))
                {
                    string name;
                    bool   loops;
                    if (MusicData.TryGetMusicData(id, out name, out loops))
                    {
                        m_Music.Add(id, new UOMusic(id, name, loops));
                    }
                    else
                    {
                        Tracer.Error("Received unknown music id {0}", id);
                        return;
                    }
                }

                ASound toPlay = m_Music[id];
                if (toPlay != m_MusicCurrentlyPlaying)
                {
                    // stop the current song
                    StopMusic();
                    // play the new song!
                    m_MusicCurrentlyPlaying = toPlay as UOMusic;
                    m_MusicCurrentlyPlaying.Play(false);
                }
            }
        }
        public void PlayMusic(int id)
        {
            if (Settings.Audio.MusicOn)
            {
                if (id < 0) // not a valid id, used to stop music.
                {
                    StopMusic();
                    return;
                }

                if (!m_Music.ContainsKey(id))
                {
                    string name;
                    bool loops;
                    if (MusicData.TryGetMusicData(id, out name, out loops))
                    {
                        m_Music.Add(id, new UOMusic(id, name, loops));
                    }
                    else
                    {
                        Tracer.Error("Received unknown music id {0}", id);
                        return;
                    }
                }

                ASound toPlay = m_Music[id];
                if (toPlay != m_MusicCurrentlyPlaying)
                {
                    // stop the current song
                    StopMusic();
                    // play the new song!
                    m_MusicCurrentlyPlaying = toPlay as UOMusic;
                    m_MusicCurrentlyPlaying.Play(false);
                }
            }
        }
 public void StopMusic()
 {
     if (m_MusicCurrentlyPlaying != null)
     {
         m_MusicCurrentlyPlaying.Stop();
         m_MusicCurrentlyPlaying.Dispose();
         m_MusicCurrentlyPlaying = null;
     }
 }
 public void StopMusic()
 {
     if (m_MusicCurrentlyPlaying != null)
     {
         // MediaPlayer.Stop();
         // Stop playing
         if (SendMediaPlayerCommand(string.Format("stop {0}", c_InternalMusicName), null, 0, IntPtr.Zero) == 0)
         {
             m_MusicCurrentlyPlaying = null;
             // close resource
             if (SendMediaPlayerCommand(string.Format("close {0}", c_InternalMusicName), null, 0, IntPtr.Zero) != 0)
             {
                 Tracer.Error("Error closing current mp3 file");
             }
         }
         else
         {
             Tracer.Error("Error stopping current mp3 file");
         }
     }
 }