Bass_ChannelIsActive

Started by Dinkleburger,

Dinkleburger

:o

The code below is sending a message to a variable
depending on the Bass_ChannelIsActive
my problem is i am doing something wrong
When i play a mp3 i always get 0
When i stop the mp3 i still get 0
so nothing is really happening
i have been up all night on this now i am left no choice but to ask for help!!!!!

// code start

if BASS_ChannelIsActive(handle) = 0 then begin
  nbSetVar('[ChanStatus]', PChar ('Channel_Not_Active'))
    end
    Else
    nbSetVar('[ChanStatus]', PChar ('Channel_Active'));

  end;

// code end
if you can help i need it shown and explained as i am still new at delphi
Thanks in advance
DB

DanaPaul


Quoteif BASS_ChannelIsActive(handle) = 0 then begin

Well, without seeing the rest of your code...  "handle" should be renamed to fChannel, or fBassStream, or My Channel, or... anything but "handle".  Reason being that TApplication and TForm and every other visual component has already defined a variable named "handle'... Application.handle, Form1.handle, MDIChild1.handle, etc.  Depending on the scope of the method that contains your code "handle" could be any one of these objects.

Additionally, you could add some error checking in your code as follows...

Case BASS_ChannelIsActive(fChannel)of
  BASS_ACTIVE_STOPPED : doPlayEnded;
  BASS_ACTIVE_PLAYING : doProgressProc;
  BASS_ACTIVE_STALLED : doSumThing;
  BASS_ACTIVE_PAUSED  : doBlinkingLabel;
  else raise
    EAbort.Create('Ian has not defined this value');
  end;
  



Dinkleburger



Still cant get it working so here is the Full Code


Var
SONG : PChar;
Songpos :Cardinal;
Chan : HSTREAM;
SineCount, Frequency, Amplitude: Real;

procedure LOAD;
var
 info:BASS_INFO;
begin
  if (BASS_GetVersion <> MAKELONG(1,8)) then
  begin
    ShowMessage('BASS version 1.8 was not loaded');
    Halt;
  end;

  if not BASS_Init(-1, 44100, BASS_DEVICE_NOSYNC, 0) then
  begin
    SHOWMESSAGE('Can''t initialize device');
    Halt;
  end
  else
  begin
    BASS_Start;
    info.size:=sizeof(BASS_INFO);
    BASS_GetInfo(info);
    if (info.flags and DSCAPS_EMULDRIVER)>0 then

  end;
end;



///////////////////////////////


Procedure CREATE;
Var
CHAN:HSTREAM;
//SONG: PChar;
begin
Song:= NIl;
nbGetVar('[SONG]', SONG);
CHAN:=0;
BASS_StreamFree(chan);

  chan := BASS_StreamCreateFile(FALSE,PChar (SONG), 0,0,0);


//////
     BASS_StreamPlay(chan, FALSE, 0);
    FreeStr (SONG);

end;




    Procedure STOP;
    Begin
    BASS_Stop;
    Bass_streamFree(Chan);
    Bass_Free;
  end;

  Procedure Pause;
        begin
        BASS_PAUSE;
        end;


       Procedure CPUTIME;
       Var
       CPU : PChar;
       Begin
CPU :=  PChar (FloatToStrF(BASS_GetCPU, ffFixed, 4, 1));
           nbSetVar('[CPU]', CPU);
            end;


            //// Active Channel
            Procedure Channel_State;
         Var
         fBaseStream : PChar;
          Begin
if BASS_ChannelIsActive(fBaseStream) = 0 then begin
  nbSetVar('[ChanStatus]', PChar ('Channel_Not_Active'))
    end
    Else
    nbSetVar('[ChanStatus]', PChar ('Channel_Active'));


end;
////////////// END OF CODE

Ok everything works exce3pt the Procedure Channel_State
thats where i am having problems
Thanks in advance DB

DanaPaul


QuoteVar Chan : HSTREAM;;
...
Procedure Channel_State;
Var
  fBaseStream : PChar;
Begin
if BASS_ChannelIsActive(fBaseStream) = 0 then begin
  nbSetVar('[ChanStatus]', PChar ('Channel_Not_Active'))
    end
    Else

    nbSetVar('[ChanStatus]', PChar ('Channel_Active'));
end;

The channel variable has been declared as a local PChar.  This is an invalid channel, or the default channel handle for a CD Device at best... nil.

Try this...

if BASS_ChannelIsActive(Chan) = 0 then begin
  


Dinkleburger

Hi DanaPaul

Still not working
When a song is playing always shows Channel_Not_Active
When i stop the song always shows Channel_Not_Active



//Code start

 Procedure Channel_State;
         Var
         chan : HSTREAM;
          Begin
          if BASS_ChannelIsActive(Chan) = 0 then begin

  nbSetVar('[ChanStatus]', PChar ('Channel_Not_Active'))
    end
    Else
     if BASS_ChannelIsActive(Chan) = 1 then begin
    nbSetVar('[ChanStatus]', PChar ('Channel_Active'));
    end;
     end;

!!

DanaPaul


QuoteStill not working

Ummm... You have variable "Chan" declared locally and globally. You need to remove the local variable declaration from your CreateFileStream section...

Procedure CREATE;
Var
CHAN:HSTREAM;

Dinkleburger

Removed the the CHAN from Procedure Create

But still doesnt work
its like its stuck on 0
DB

Irrational86

I think i know why, on all your codes and procedures, you declare a CHAN variable local, remove all the local declarations of a variable CHAN and try...that should fix it..

Dinkleburger

:D
  Thankyou DanaPaul and XMinioNX

  This code works i hope the forum doesnt mind but i am posting the working code, just incase theres another one of me another day *SMILES*

Var
SONG : PChar;
Songpos :Cardinal;
MP3:HSTREAM;
//Chan : HSTREAM;
SineCount, Frequency, Amplitude: Real;

procedure LOAD;
var
 info:BASS_INFO;
begin
  if (BASS_GetVersion <> MAKELONG(1,8)) then
  begin
    ShowMessage('BASS version 1.8 was not loaded');
    Halt;
  end;

  if not BASS_Init(-1, 44100, BASS_DEVICE_NOSYNC, 0) then
  begin
    SHOWMESSAGE('Can''t initialize device');
    Halt;
  end
  else
  begin
    BASS_Start;
    info.size:=sizeof(BASS_INFO);
    BASS_GetInfo(info);
    if (info.flags and DSCAPS_EMULDRIVER)>0 then

  end;
end;



///////////////////////////////


Procedure CREATE;
//Var
//MP3:HSTREAM;
//SONG: PChar;
begin
//CHAN:=0;
Song:= NIl;
nbGetVar('[SONG]', SONG);

//BASS_StreamFree(chan);

  MP3 :=BASS_StreamCreateFile(FALSE,PChar (SONG), 0,0,0);


//////
     BASS_StreamPlay(MP3, FALSE, 0);
    FreeStr (SONG);

end;




    Procedure STOP;
    Begin
    BASS_Stop;
 //   Bass_streamFree(MP3);
    Bass_Free;
  end;

  Procedure Pause;
        begin
        BASS_PAUSE;
        end;


       Procedure CPUTIME;
       Var
       CPU : PChar;
       Begin
CPU :=  PChar (FloatToStrF(BASS_GetCPU, ffFixed, 4, 1));
           nbSetVar('[CPU]', CPU);
            end;


            //// Active Channel
            Procedure Channel_State;
        // Var
       //  chan : HSTREAM;
         Begin

          if BASS_ChannelIsActive(MP3) = 0 then begin

  nbSetVar('[ChanStatus]', PChar ('Channel_Not_Active'))
    end
    Else
     if BASS_ChannelIsActive(MP3) = 1 then begin
    nbSetVar('[ChanStatus]', PChar ('Channel_Active'));
    end;

end;