Beispiel #1
0
 private void BtnChannelMode_OnClick(object sender, RoutedEventArgs e)
 {
     if (mChannelMode == WaveOutChannelMode.Default)
     {
         mChannelMode           = WaveOutChannelMode.Left;
         BtnChannelMode.Content = "L";
         ImgRight.Opacity       = 0.5;
         ImgLeft.Opacity        = 1;
     }
     else if (mChannelMode == WaveOutChannelMode.Left)
     {
         mChannelMode           = WaveOutChannelMode.Right;
         BtnChannelMode.Content = "R";
         ImgLeft.Opacity        = 0.5;
         ImgRight.Opacity       = 1;
     }
     else
     {
         mChannelMode           = WaveOutChannelMode.Default;
         BtnChannelMode.Content = "D";
         ImgLeft.Opacity        = 1;
         ImgRight.Opacity       = 1;
     }
     if (mWaveOut != null)
     {
         mWaveOut.ChannelMode = mChannelMode;
     }
 }
Beispiel #2
0
        /// <summary>
        /// 实现简易播放器,功能:播放控制,快进快退,音量控制,声道控制以及波形图显示
        /// </summary>
        public AudioPlayer()
        {
            InitializeComponent();

            Loaded                        += AudioPlayer_Loaded;
            Unloaded                      += AudioPlayer_Unloaded;
            BtnOpen.Click                 += BtnOpen_Click;
            BtnPlay.Click                 += BtnPlay_Click;
            BtnPause.Click                += BtnPause_Click;
            BtnStop.Click                 += BtnStop_Click;
            BtnSlower.Click               += BtnSlower_Click;
            BtnFaster.Click               += BtnFaster_Click;
            BtnChannelMode.Click          += BtnChannelMode_Click;
            BtnClose.Click                += BtnClose_Click;
            SliderVolume.LostMouseCapture += SliderVolume_LostMouseCapture;
            SliderVolume.MouseUp          += SliderVolume_MouseUp;
            //SliderPosition.LostMouseCapture += SliderPosition_LostMouseCapture;
            SliderPosition.MouseUp   += SliderPosition_MouseUp;
            SliderPosition.MouseMove += SliderPosition_MouseMove;

            mTimer          = new Timer();
            mTimer.Interval = 100;
            mTimer.Elapsed += mTimer_Elapsed;
            mRate           = 1.0;
            mVolumn         = 1;
            mChannelMode    = WaveOutChannelMode.Default;
            mState          = "11111111111";
        }
Beispiel #3
0
        /// <summary>
        /// creates a new wavebuffer
        /// </summary>
        /// <param name="hWaveOut">WaveOut device to write to</param>
        /// <param name="bufferSize">Buffer size in bytes</param>
        /// <param name="bufferFillStream">Stream to provide more data</param>
        /// <param name="waveOutLock">Lock to protect WaveOut API's from being called on >1 thread</param>
        public WaveOutBuffer(IntPtr hWaveOut, Int32 bufferSize, IWaveProvider bufferFillStream, object waveOutLock)
        {
            this.bufferSize  = bufferSize;
            buffer           = new byte[bufferSize];
            hBuffer          = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            this.hWaveOut    = hWaveOut;
            waveStream       = bufferFillStream;
            this.waveOutLock = waveOutLock;

            // Added by charley at 2013/4/9
            ChannelMode = WaveOutChannelMode.Default;
            mVolumnSize = 1;
            mLeftVolumn = true;
            mVolumnSize = bufferFillStream.WaveFormat.BitsPerSample / 8;

            header              = new WaveHeader();
            hHeader             = GCHandle.Alloc(header);
            header.dataBuffer   = hBuffer.AddrOfPinnedObject();
            header.bufferLength = bufferSize;
            header.loops        = 1;
            hThis           = GCHandle.Alloc(this);
            header.userData = (IntPtr)hThis;
            lock (waveOutLock)
            {
                MmException.Try(WaveInterop.waveOutPrepareHeader(hWaveOut, header, Marshal.SizeOf(header)), "waveOutPrepareHeader");
            }
        }
Beispiel #4
0
        /// <summary>
        /// 实现简易播放器,功能:播放控制,快进快退,音量控制,声道控制以及波形图显示
        /// </summary>
        public AudioPlayer()
        {
            InitializeComponent();

            mTimer          = new Timer();
            mTimer.Interval = 100;
            mTimer.Elapsed += mTimer_Elapsed;
            mRate           = 1.0;
            mVolumn         = 1;
            mChannelMode    = WaveOutChannelMode.Default;
            mState          = "11111111111";
        }
Beispiel #5
0
 void BtnChannelMode_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (mChannelMode == WaveOutChannelMode.Default)
         {
             mChannelMode           = WaveOutChannelMode.Left;
             BtnChannelMode.Content = "L";
             ImgRight.Opacity       = 0.5;
             ImgLeft.Opacity        = 1;
         }
         else if (mChannelMode == WaveOutChannelMode.Left)
         {
             mChannelMode           = WaveOutChannelMode.Right;
             BtnChannelMode.Content = "R";
             ImgLeft.Opacity        = 0.5;
             ImgRight.Opacity       = 1;
         }
         else
         {
             mChannelMode           = WaveOutChannelMode.Default;
             BtnChannelMode.Content = "D";
             ImgLeft.Opacity        = 1;
             ImgRight.Opacity       = 1;
         }
         if (mWaveOut != null)
         {
             mWaveOut.ChannelMode = mChannelMode;
         }
     }
     catch (Exception ex)
     {
         OptReturn optReturn = new OptReturn();
         optReturn.Code    = Defines.RET_FAIL;
         optReturn.Message = ex.Message;
         ShowException(optReturn);
     }
 }
Beispiel #6
0
        private void Init()
        {
            try
            {
                mUrl            = string.Empty;
                mTimer.Interval = 100;
                mRate           = 1.0;
                mChannelMode    = WaveOutChannelMode.Default;
                State           = "11111111111";
                Volume          = 1;
                mIsDraging      = false;

                Title               = string.Empty;
                LbRate              = mRate.ToString("0.0");
                LbVolume            = Volume.ToString("0.0");
                LbCurrentTime       = "00:00:00";
                LbTotalTime         = "00:00:00";
                IsImageLeftVisible  = true;
                IsImageRightVisible = true;
                IsVolumeVisible     = true;
            }
            catch { }
        }
Beispiel #7
0
        private void BtnChannelMode_Click()
        {
            OptReturn optReturn;

            try
            {
                var btnChannelMode = mListRightButtons.FirstOrDefault(b => b.Name == "ChannelMode");
                if (btnChannelMode == null)
                {
                    return;
                }
                if (mChannelMode == WaveOutChannelMode.Default)
                {
                    mChannelMode           = WaveOutChannelMode.Left;
                    btnChannelMode.Display = "L";
                    if (mImageLeft != null)
                    {
                        mImageLeft.Opacity = 1;
                    }
                    if (mImageRight != null)
                    {
                        mImageRight.Opacity = 0.5;
                    }
                }
                else if (mChannelMode == WaveOutChannelMode.Left)
                {
                    mChannelMode           = WaveOutChannelMode.Right;
                    btnChannelMode.Display = "R";
                    if (mImageLeft != null)
                    {
                        mImageLeft.Opacity = 0.5;
                    }
                    if (mImageRight != null)
                    {
                        mImageRight.Opacity = 1;
                    }
                }
                else
                {
                    mChannelMode           = WaveOutChannelMode.Default;
                    btnChannelMode.Display = "D";
                    if (mImageLeft != null)
                    {
                        mImageLeft.Opacity = 1;
                    }
                    if (mImageRight != null)
                    {
                        mImageRight.Opacity = 1;
                    }
                }
                if (mWaveOut != null)
                {
                    mWaveOut.ChannelMode = mChannelMode;
                }
            }
            catch (Exception ex)
            {
                optReturn         = new OptReturn();
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
                ShowException(optReturn);
            }
        }