聲音文件

 

 /// <summary>
       ///  //sound響起的時間
       /// </summary>
       /// <param name="pSoundResName">聲音源文件名稱</param>
       /// <param name="pDuration">響聲時間s</param>
       /// <returns>boolean</returns>
       public Boolean PlaySound(String pSoundResName, int pDuration)
       {
           try
           {
               String strpath = ResourcesManager.Instance().GetResource(pSoundResName);
               player = new SoundPlayer(strpath);
               fTimer.Interval = 2000;
               fTimer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
               fTimer.Enabled = true; //是否觸發Elapsed事件
               fTimer.Interval = pDuration * 1000;
               fTimer.Start();
               player.PlayLooping();
               return true;
           }
           catch (Exception ex)
           {
               return false;
           }
       }
       /// <summary>
       /// 結束sound
       /// </summary>
       /// <returns></returns>
       public Boolean StopCurrentSound()
       {
           Boolean repeat = false;

           if (player != null)
           {
               player.Stop();
               player.Dispose();
               repeat = true;
           }

           return repeat;

       }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章