protected virtual void OnFree(object sender, EventArgs e)
 {
     if (!this.IsInitialized)
     {
         return;
     }
     BassZipStream.Free();
     this.IsInitialized = false;
 }
Ejemplo n.º 2
0
        public void Test002(string archiveName, string entryPath, string password)
        {
            if (!this.Cleanup)
            {
                Assert.Ignore("Requires clean state.");
            }

            var fileName = Path.Combine(Location, "Media", archiveName);
            var index    = Utils.GetEntryIndex(archiveName, entryPath);

            if (!Bass.Init(Bass.DefaultDevice))
            {
                Assert.Fail(string.Format("Failed to initialize BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            if (!BassZipStream.Init())
            {
                Assert.Fail("Failed to initialize ZIPSTREAM.");
            }

            if (string.IsNullOrEmpty(password))
            {
                Utils.PasswordHandler.Reset();
            }
            else
            {
                Utils.PasswordHandler.Set(fileName, password, 5000);
            }

            try
            {
                var sourceChannel = BassZipStream.CreateStream(fileName, index);
                Assert.AreEqual(0, sourceChannel);
                Assert.AreEqual(ArchiveError.E_PASSWORD_REQUIRED, ArchiveError.GetLastError());
            }
            finally
            {
                if (!BassZipStream.Free())
                {
                    Assert.Fail(string.Format("Failed to free ZIPSTREAM: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }

                if (!Bass.Free())
                {
                    Assert.Fail(string.Format("Failed to free BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }
            }
        }
        public override IBassStream CreateInteractiveStream(PlaylistItem playlistItem, IEnumerable <IBassStreamAdvice> advice, BassFlags flags)
        {
            var fileName  = default(string);
            var entryName = default(string);

            if (!ArchiveUtils.ParseUrl(playlistItem.FileName, out fileName, out entryName))
            {
                //This shouldn't happen as CanCreateStream would have returned false.
                return(BassStream.Empty);
            }
            var index = default(int);

            if (!ArchiveUtils.GetEntryIndex(fileName, entryName, out index))
            {
                //The associated entry was not found.
                return(BassStream.Empty);
            }
            if (this.Output != null && this.Output.PlayFromMemory)
            {
                Logger.Write(this, LogLevel.Warn, "This provider cannot play from memory.");
            }
retry:
            var channelHandle = BassZipStream.CreateStream(fileName, index, Flags: flags);

            if (channelHandle == 0)
            {
                switch (ArchiveError.GetLastError())
                {
                case ArchiveError.E_PASSWORD_REQUIRED:
                    Logger.Write(this, LogLevel.Warn, "Invalid password for \"{0}\".", fileName);
                    if (this.PasswordBehaviour != null)
                    {
                        var cancelled = this.PasswordBehaviour.WasCancelled(fileName);
                        this.PasswordBehaviour.Reset(fileName);
                        if (!cancelled)
                        {
                            goto retry;
                        }
                    }
                    break;
                }
            }
            return(this.CreateInteractiveStream(channelHandle, advice, flags));
        }
        protected virtual void OnInit(object sender, EventArgs e)
        {
            if (!this.Enabled)
            {
                return;
            }
            var flags = BassFlags.Decode;

            if (this.Output.Float)
            {
                flags |= BassFlags.Float;
            }
            BassUtils.OK(BassZipStream.Init());
            BassUtils.OK(BassZipStream.SetConfig(BassZipStreamAttribute.BufferMin, this.BufferMin));
            BassUtils.OK(BassZipStream.SetConfig(BassZipStreamAttribute.BufferTimeout, this.BufferTimeout));
            BassUtils.OK(BassZipStream.SetConfig(BassZipStreamAttribute.DoubleBuffer, this.DoubleBuffer));
            this.IsInitialized = true;
            Logger.Write(this, LogLevel.Debug, "BASS ZIPSTREAM Initialized.");
        }
Ejemplo n.º 5
0
        public void Test001(string archiveName, string entryPath, long length)
        {
            var fileName = Path.Combine(Location, "Media", archiveName);
            var index    = Utils.GetEntryIndex(archiveName, entryPath);

            if (!Bass.Init(Bass.DefaultDevice))
            {
                Assert.Fail(string.Format("Failed to initialize BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
            }

            if (!BassZipStream.Init())
            {
                Assert.Fail("Failed to initialize ZIPSTREAM.");
            }

            try
            {
                var sourceChannel = BassZipStream.CreateStream(fileName, index);
                if (sourceChannel == 0)
                {
                    Assert.Fail(string.Format("Failed to create source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }

                Assert.AreEqual(length, Bass.ChannelGetLength(sourceChannel));

                if (!Bass.ChannelPlay(sourceChannel))
                {
                    Assert.Fail(string.Format("Failed to play the source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }

                //Play for a bit.
                global::System.Threading.Thread.Sleep(10000);

                if (!Bass.ChannelSetPosition(sourceChannel, Bass.ChannelGetLength(sourceChannel) - Bass.ChannelSeconds2Bytes(sourceChannel, 10)))
                {
                    Assert.Fail(string.Format("Failed to seek the source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }

                //Play for a bit.
                while (Bass.ChannelIsActive(sourceChannel) == PlaybackState.Playing)
                {
                    global::System.Threading.Thread.Sleep(1000);
                }

                //TODO: Not working, reported position is greater than the length?
                //Assert.AreEqual(length, Bass.ChannelGetPosition(sourceChannel));

                if (!Bass.StreamFree(sourceChannel))
                {
                    Assert.Fail(string.Format("Failed to free the source stream: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }
            }
            finally
            {
                if (!BassZipStream.Free())
                {
                    Assert.Fail(string.Format("Failed to free ZIPSTREAM: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }

                if (!Bass.Free())
                {
                    Assert.Fail(string.Format("Failed to free BASS: {0}", Enum.GetName(typeof(Errors), Bass.LastError)));
                }
            }
        }