예제 #1
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)));
                }
            }
        }
        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.");
        }
예제 #3
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)));
                }
            }
        }