예제 #1
0
        public void PlayBackgroundMusic(int mfxID)
        {
            if (mfxID < 1 || mfxID >= m_music.Count)
            {
                throw new ArgumentOutOfRangeException("mfxID", "The MFX id is out of range. Use the 1-based index that matches the number in the file name.");
            }

            Action _func = () =>
            {
                m_songPlayer.Stop();
                m_songPlayer.Close();
                m_songPlayer.Open(m_music[mfxID - 1]);
                m_songPlayer.Play();
            };

            //when changing the map, the background music will be played from a different thread than the main
            //	one since it is all being done in a callback from the received network data. This requires a
            //	dispatcher to invoke the song change on the m_songPlayer, otherwise an exception is thrown because
            //	the thread does not 'own' the m_songPlayer object.
            if (m_dispatcher.Thread != Thread.CurrentThread)
            {
                m_dispatcher.BeginInvoke(_func);
            }
            else
            {
                _func();
            }
        }
예제 #2
0
 public void Stop(ProgressBar progress)
 {
     _player.Stop();
     i = 0;
     progress.Value = 0;
     sync.Stop();
 }
예제 #3
0
 private void playWindows(String note_octave)
 {
     System.Windows.Media.MediaPlayer mp = (MediaPlayer)deviceMap[note_octave];
     mp.Stop();
     mp.Position = new TimeSpan(0);
     mp.Play();
 }
예제 #4
0
 private void playSound(Uri path)
 {
     new Thread(() => {
         var c = new System.Windows.Media.MediaPlayer();
         c.Open(path);
         c.Play();
         Thread.Sleep(2000);
         c.Stop();
     }).Start();
 }
예제 #5
0
        public void Stop()
        {
            _player.Stop();
            _positionTimer.Stop();

            IsPlaying = false;
            IsPaused  = false;
            IsStopped = true;

            Position = 0.0;
        }
예제 #6
0
        /// <summary>
        /// 停止播放声音
        /// </summary>
        public static void StopAudio()
        {
            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    if (_player != null)
                    {
                        _player.Stop();
                    }

                    _player = null;
                }
                catch (Exception ex)
                {
                    Log.SaveLog("Core Common_StopAudio", ex.ToString());
                }
            }));
        }
예제 #7
0
 private void btnStop_Click(object sender, RoutedEventArgs e)
 {
     time = mediaPlayer.Position;
     mediaPlayer.Stop();
 }
예제 #8
0
 public void Stop()
 {
     _internalPlayer.Stop();
 }
예제 #9
0
파일: Global.cs 프로젝트: jiailiuyan/Jisons
        /// <summary>
        /// 视频截取第一帧
        /// </summary>
        /// <param name="videopath">要截屏的视频路径</param>
        /// <param name="savepath">要把截屏保存到得路径</param>
        /// <param name="rect">截屏所得图片框大小</param>
        public static void GetVideoThumb(string videopath, string savepath, Rect rect)
        {
            //打开视频
            MediaPlayer _player = new MediaPlayer();
            _player.Volume = 0;
            _player.Open(new Uri(videopath));
            _player.Play();

            //截取视频第一帧
            Thread.Sleep(1300);
            RenderTargetBitmap target = new RenderTargetBitmap((int)rect.Width, (int)rect.Height, 1 / 100, 1 / 100, PixelFormats.Pbgra32);
            DrawingVisual visual = new DrawingVisual();
            DrawingContext context = visual.RenderOpen();
            context.DrawVideo(_player, new Rect(0, 0, (int)rect.Width, (int)rect.Height));
            context.Close();

            target.Render(visual);

            //移除视频
            _player.Stop();
            _player.Position = TimeSpan.FromSeconds(0);
            _player.Close();
            _player = null;

            //保存第一帧
            BitmapEncoder encoder = new TiffBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(target));

            FileStream fs = new FileStream(savepath, FileMode.Create);
            encoder.Save(fs);
            fs.Close();
        }
        void frameThread_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = (BackgroundWorker)sender;

             MediaPlayer myPlayer = new MediaPlayer();
             myPlayer.Open(parameters.SourceUri);
             myPlayer.Volume = 0;
             myPlayer.Play();

             while (myPlayer.NaturalVideoWidth < 1)
            System.Threading.Thread.Sleep(100);

             myState = ScallopSensorState.Active;
             this.StatusChanged(this, new ScallopSensorStatusChangedEventArgs(ScallopSensorState.Idle, ScallopSensorState.Active));

             RenderTargetBitmap rtb = new RenderTargetBitmap(myPlayer.NaturalVideoWidth, myPlayer.NaturalVideoHeight,
                                                           96, 96, PixelFormats.Pbgra32);

             while (true)
             {
            if (bw.CancellationPending == true)
            {
               myPlayer.Stop();
               e.Cancel = true;
               return;
            }

            DrawingVisual dv = new DrawingVisual();
            DrawingContext dc = dv.RenderOpen();

            dc.DrawVideo(myPlayer, new Rect(0, 0, myPlayer.NaturalVideoWidth, myPlayer.NaturalVideoHeight));
            dc.Close();

            rtb.Clear();
            rtb.Render(dv);

            BitmapFrame bmp = BitmapFrame.Create(rtb);

            switch (parameters.FrameFormat)
            {
               case ("System.Drawing.Bitmap"):

                  using (MemoryStream memoryStream = new MemoryStream())
                  {
                     //bitmapEncoder.Frames.Add(BitmapFrame.Create(bmp));
                     PngBitmapEncoder bitmapEncoder = new PngBitmapEncoder();
                     bitmapEncoder.Frames.Add(bmp);
                     bitmapEncoder.Save(memoryStream);
                     memoryStream.Flush();

                     using (Bitmap bmp2 = Bitmap.FromStream(memoryStream) as Bitmap,
                                   bmp3 = new Bitmap(bmp2.Width,bmp2.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                     {
                        bmp3.SetResolution(bmp2.HorizontalResolution, bmp2.VerticalResolution);

                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp3))
                        {
                           g.DrawImage(bmp2, 0, 0);
                        }

                        if (this.Data != null)
                           this.Data(this, new ScallopSensorDataEventArgs((System.Drawing.Bitmap)bmp3.Clone(), "new frame"));
                     }

                  }
                  break;

               case ("System.Windows.Media.Imaging.BitmapSource"):
                  if (this.Data != null)
                     this.Data(this, new ScallopSensorDataEventArgs(bmp as BitmapSource, "new frame"));
                  break;
            }

            if (myPlayer.Position >= myPlayer.NaturalDuration)
            {
               myPlayer.Stop();
               myPlayer.Position = TimeSpan.Zero;
               myPlayer.Play();
            }
             }
        }
예제 #11
0
 public void Stop()
 {
     player.Stop();
 }
예제 #12
0
 /// <summary>
 /// Funkcja wątku odtwarzania muzyki w tle
 /// </summary>
 public static void MusicThreadFunc()
 {
     try
     {
         mp = new MediaPlayer();
         mp.Open(new System.Uri(Path.GetFullPath(@"background_music.wav")));
         mp.Volume = (double)MusicVolumeTrackBar.Value / 10;
         mp.Play();
     }
     catch { }
     while (!music_stop)
     {
         if (music_changed)
         {
             if (MuteCheckbox.Checked)
             {
                 mp.Volume = 0;
                 music_changed = false;
             }
             else
             {
                 mp.Volume = (double)MusicVolumeTrackBar.Value / 10;
                 music_changed = false;
             }
         }
     }
     if(mp!=null)
     mp.Stop();
        music_stop = false;
 }
예제 #13
0
        /// <summary>
        /// Funkcja watku odtwarzania pojedynczych dzwiekow
        /// </summary>
        public static void SoundThreadFunc()
        {
            try
            {

                sp = new MediaPlayer();
                sp.Open(new System.Uri(Path.GetFullPath(@"found.wav")));
                sp.Volume = (double)musicVolTrackbar.Value / 10;
                sp.Play();

            }
            catch { }
            while (!sound_stop)
            {
                if (sound_changed)
                {
                    if (MuteCheckbox.Checked)
                    {
                        sp.Volume = 0;
                        sound_changed = false;
                    }
                    else
                    {
                        sp.Open(new System.Uri(Path.GetFullPath(@"found.wav")));
                        sp.Volume = (double)musicVolTrackbar.Value / 10;
                        sp.Play();
                        sound_changed = false;
                    }
                }
            }
            if (sp != null)
            sp.Stop();
            sound_stop = false;
        }
예제 #14
0
 public void Stop()
 {
     _mp.Stop();
 }
예제 #15
0
 /// <summary>
 /// Stops the music player's track.
 /// </summary>
 public static void StopMusic()
 {
     MusicPlayer.Stop();
 }