Пример #1
0
        public override bool Wrap(IBassStreamProvider provider, int channelHandle, IEnumerable <IBassStreamAdvice> advice, BassFlags flags, out IBassStream stream)
        {
            var offset = default(long);
            var length = default(long);

            if (this.Offset != TimeSpan.Zero)
            {
                offset = Bass.ChannelSeconds2Bytes(channelHandle, this.Offset.TotalSeconds);
            }
            if (this.Length != TimeSpan.Zero)
            {
                length = Bass.ChannelSeconds2Bytes(channelHandle, this.Length.TotalSeconds);
            }
            if (offset != 0 || length != 0)
            {
                if (length == 0)
                {
                    length = Bass.ChannelGetLength(channelHandle, PositionFlags.Bytes) - offset;
                }
                stream = new BassStream(
                    provider,
                    BassSubstream.CreateStream(channelHandle, offset, length, flags),
                    length,
                    advice,
                    flags
                    );
                return(true);
            }
            stream = null;
            return(false);
        }
Пример #2
0
        public async Task <IBassStream> CreateStream(PlaylistItem playlistItem, bool immidiate, BassFlags flags)
        {
#if NET40
            this.Semaphore.Wait();
#else
            await this.Semaphore.WaitAsync().ConfigureAwait(false);
#endif
            try
            {
                foreach (var provider in this.Providers.Values)
                {
                    if (!provider.CanCreateStream(playlistItem))
                    {
                        continue;
                    }
                    var channelHandle = await provider.CreateStream(playlistItem, flags).ConfigureAwait(false);

                    if (channelHandle != 0)
                    {
                        return(new BassStream(provider, channelHandle));
                    }
                    else
                    {
                        return(BassStream.Error(Bass.LastError));
                    }
                }
            }
            finally
            {
                this.Semaphore.Release();
            }
            return(BassStream.Empty);
        }
Пример #3
0
        protected virtual IBassStream CreateBasicStream(int channelHandle, IEnumerable <IBassStreamAdvice> advice, BassFlags flags)
        {
            if (channelHandle == 0)
            {
                Logger.Write(this, LogLevel.Debug, "Failed to create stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError));
                return(BassStream.Error(Bass.LastError));
            }
            var stream = default(IBassStream);

            foreach (var advisory in advice)
            {
                if (advisory.Wrap(this, channelHandle, advice, flags, out stream))
                {
                    break;
                }
            }
            if (stream == null)
            {
                stream = new BassStream(this, channelHandle, Bass.ChannelGetLength(channelHandle, PositionFlags.Bytes), advice, flags);
            }
            return(stream);
        }