PDA

View Full Version : BASS- how to know when song is complete?



DarknessX
11-05-2007, 12:50 AM
Well? Can anyone give me some code examples on knowing when a playing audio file is complete, without OOP or classes? IE, my current setup is...


Procedure PlaySound;
begin
music_file := ' ';
StrPCopy(music_file,musicfile[x]);
//music_file := 'C:\Projects\Task Scheduler\test.wav';
init_stuff;
load_song;
BASS_setvolume(volume[x]);
totallength := round(BASS_ChannelBytes2Seconds(stream,BASS_Stream GetLength(stream)));
Writeln('Playing file ',MUSIC_FILE,'.');
readkey; //Instead of readkey, I want to check if song is finished, and if yes, continue procedure.
stop_song;
done_stuff;
end;


And in case your wondering, the music_file := ' ..' is like that because if the size of the var is too small (empty) the StrPCopy won't work properly...

DarknessX
12-05-2007, 11:24 PM
Well, I found a solution. But, it opens another problem... Which I also found a solution to :P


Procedure PlaySound;
begin
music_file := ' ';
StrPCopy(music_file,musicfile[x]);
//music_file := 'C:\Projects\Task Scheduler\test.wav';
init_stuff;
load_song;
BASS_setvolume({volume[x]}100);
totallength := round(BASS_ChannelBytes2Seconds(stream,BASS_Stream GetLength(stream)));
textcolor(12);
Writeln('Playing file ',MUSIC_FILE,'.');
textcolor(7);
play_song;
y := 1;
repeat
y := y+1;
delay(1000);
until y = totallength+2;
y := 0;
stop_song;
done_stuff;
textcolor(7);
end;


Now, how I did it, was using the totallength := round(BASS_ChannelBytes2Seconds(stream,BASS_Stream GetLength(stream))); which gets the totallength, in seconds, of the song, and made a repeat.. until which made y increment by 1 every second, until y was equal to totallength plus 2 seconds... (to make sure none of the song/sound is cut off). So, yeah. Now I have the problem that the delay forces the program to stop, so I'm just gonna make it launch an external program which plays the sound and such.