示例#1
0
 protected override void FreeBASS()
 {
     this._waveInfo = null;
     base.FreeBASS();
     if (base.HandleValid())
     {
         WavHelper.BASS_ChannelRemoveSync(base._handle, this._playEndSyncHandle);
     }
 }
示例#2
0
        //private void PlayPositionChangedNotify(int handle, int channel, int data, IntPtr user)
        //{
        //    WavLoger.OnRaiseLog(this, "PlayPositionChangedNotify");
        //}

        private void PlayEndNotify(int handle, int channel, int data, IntPtr user)
        {
            this._waveInfo = null;

            var handler = this.PlayEnd;

            if (handler != null)
            {
                handler(this, new PlayEndArgs(this._fileName));
            }
        }
示例#3
0
        /// <summary>
        /// 播放状态改变通知
        /// </summary>
        protected override void OnPlayStatusChanged()
        {
            base.OnPlayStatusChanged();

            var state = WavHelper.ChannelIsActive(base._handle);

            if (state != BASSActive.BASS_ACTIVE_PAUSED &&
                state != BASSActive.BASS_ACTIVE_PAUSED_DEVICE &&
                state != BASSActive.BASS_ACTIVE_PLAYING)
            {
                this._waveInfo = null;
            }
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="waveInfo">音频信息</param>
        /// <param name="bufferCapcity">缓存容量,小于等于0自动计算</param>
        public StreamSoundPlayer(WaveInfo waveInfo, int bufferCapcity = -1)
            : base(SoundPlayerType.Stream)
        {
            this._waveInfo = waveInfo;
            int bitByteCount;


            BASSFlag flags;

            switch (waveInfo.SampleBit)
            {
            case SampleType.Sample8Bit:
                flags        = BASSFlag.BASS_DEFAULT | BASSFlag.BASS_SAMPLE_8BITS;
                bitByteCount = 1;
                break;

            case SampleType.Sample16Bit:
                flags        = BASSFlag.BASS_DEFAULT;
                bitByteCount = 2;
                break;

            case SampleType.Sample32Bit:
                flags        = BASSFlag.BASS_DEFAULT | BASSFlag.BASS_SAMPLE_FLOAT;
                bitByteCount = 4;
                break;

            default:
                throw new NotImplementedException($"未实现的采样类型:{waveInfo.SampleBit.ToString()}");
            }

            if (bufferCapcity == -1)
            {
                bufferCapcity = waveInfo.SampleRate * waveInfo.ChannelCount * bitByteCount * 10;//默认缓存10秒数据
            }

            if (bufferCapcity > 0)
            {
                this._buffer = new byte[bufferCapcity];
            }

            this._streamProc = new STREAMPROC(this.StreamProcCallback);
            base._handle     = WavHelper.StreamCreate(waveInfo.SampleRate, waveInfo.ChannelCount, flags, this._streamProc, IntPtr.Zero);
            //base._device = WavHelper.ChannelGetDevice(base._handle);
        }