在 qb64 中加载音频文件时可能加载条或百分比
Loading bar or percentage possible while loading audio file in qb64
这是我目前拥有的
PRINT "Loading..."
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file
我想让它做的是在加载时增加一个百分比,如果可能的话,
由于不知道要加载的文件大小,所以只能提供:
REM sample to display approx. percent while loading file
CLS
PRINT "Loading..."
PRINT "000%";
ON TIMER(1) GOSUB DisplayPercent
TIMER ON
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file
DO WHILE INKEY$="":LOOP 'wait while sound plays
TIMER OFF 'turn off timer after entire file played
END
DisplayPercent:
P = P + 10
IF P <= 100 THEN
FOR L = 1 TO 4
PRINT CHR$(29); " "; CHR$(29);
NEXT
PRINT RIGHT$("000" + MID$(STR$(P), 2), 3); "%";
END IF
RETURN
好的,我已经设法在 QB64 v1.2 中使用它获得正在播放的 .mp3 文件的百分比:
REM sample to display approx. percent while loading/playing file.
CLS
PRINT "Loading..."
t1 = _FREETIMER
soundHandle& = _SNDOPEN("music.mp3", "LEN") 'opens the sound file
IF soundHandle& = 0& THEN PRINT "Error opening file": END
x& = _SNDLEN(soundHandle&) 'get length of file in seconds
PRINT "Length:"; x&; "seconds."
PRINT "000%";
x! = x& / 100 'calculate percent
IF x! = 0! THEN x! = 1!
ON TIMER(t1, x!) GOSUB DisplayPercent
TIMER(t1) ON
_SNDPLAY soundHandle&
DO UNTIL INKEY$ <> ""
_LIMIT 50
x% = _SNDPLAYING(soundHandle&) 'check when file has finished playing
IF x% = 0 THEN EXIT DO
LOOP
_SNDCLOSE (soundHandle&)
TIMER(t1) OFF
TIMER(t1) FREE
END
DisplayPercent:
P = P + 1
IF P > 100 THEN RETURN
FOR L = 1 TO 4
PRINT CHR$(29); " "; CHR$(29);
NEXT
PRINT RIGHT$("000" + MID$(STR$(P), 2), 3); "%";
RETURN
捕获键盘输入和调用菜单时播放 .mp3 文件的另一个示例:子例程:(并在标题栏上显示百分比);
REM sample to display approx. percent in title bar while playing file
CLS
COLOR 15
PRINT "Playing..."
t1 = _FREETIMER
Filename$ = "music.mp3"
soundHandle& = _SNDOPEN(Filename$, "LEN") 'opens the sound file
IF soundHandle& = 0& THEN PRINT "Error opening file": END
x& = _SNDLEN(soundHandle&) 'get length of file in seconds
COLOR 14
PRINT "Length:"; x&; "seconds."
_TITLE "000%"
x! = x& / 100 'calculate percent
IF x! = 0! THEN x! = 1!
ON TIMER(t1, x!) GOSUB DisplayPercent
TIMER(t1) ON
_SNDPLAY soundHandle&
Playing = -1
DO
_LIMIT 50
x$ = INKEY$
IF x$ = CHR$(27) THEN EXIT DO
IF LEN(x$) THEN GOSUB menu
IF Playing THEN
x% = _SNDPLAYING(soundHandle&) 'check when file has finished playing
IF x% = 0 THEN
Playing = 0
COLOR 14
PRINT "Music playback finished.."
_SNDCLOSE (soundHandle&)
TIMER(t1) OFF
TIMER(t1) FREE
END IF
END IF
LOOP
IF Playing THEN
_SNDSTOP soundHandle&
_SNDCLOSE (soundHandle&)
TIMER(t1) OFF
TIMER(t1) FREE
END IF
COLOR 7
END
' trap input and do stuff here:
menu:
COLOR 15
IF LEN(x$) = 2 THEN
PRINT "You pressed: 0"; ASC(RIGHT$(x$, 1))
ELSE
PRINT "You pressed:"; ASC(x$)
END IF
RETURN
' display filename and percent on title bar
DisplayPercent:
P = P + 1
IF P > 100 THEN P = 101: RETURN ' check overflow
_TITLE "Playing " + Filename$ + " - " + RIGHT$("000" + MID$(STR$(P), 2), 3) + "%"
RETURN
这是我目前拥有的
PRINT "Loading..."
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file
我想让它做的是在加载时增加一个百分比,如果可能的话,
由于不知道要加载的文件大小,所以只能提供:
REM sample to display approx. percent while loading file
CLS
PRINT "Loading..."
PRINT "000%";
ON TIMER(1) GOSUB DisplayPercent
TIMER ON
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file
DO WHILE INKEY$="":LOOP 'wait while sound plays
TIMER OFF 'turn off timer after entire file played
END
DisplayPercent:
P = P + 10
IF P <= 100 THEN
FOR L = 1 TO 4
PRINT CHR$(29); " "; CHR$(29);
NEXT
PRINT RIGHT$("000" + MID$(STR$(P), 2), 3); "%";
END IF
RETURN
好的,我已经设法在 QB64 v1.2 中使用它获得正在播放的 .mp3 文件的百分比:
REM sample to display approx. percent while loading/playing file.
CLS
PRINT "Loading..."
t1 = _FREETIMER
soundHandle& = _SNDOPEN("music.mp3", "LEN") 'opens the sound file
IF soundHandle& = 0& THEN PRINT "Error opening file": END
x& = _SNDLEN(soundHandle&) 'get length of file in seconds
PRINT "Length:"; x&; "seconds."
PRINT "000%";
x! = x& / 100 'calculate percent
IF x! = 0! THEN x! = 1!
ON TIMER(t1, x!) GOSUB DisplayPercent
TIMER(t1) ON
_SNDPLAY soundHandle&
DO UNTIL INKEY$ <> ""
_LIMIT 50
x% = _SNDPLAYING(soundHandle&) 'check when file has finished playing
IF x% = 0 THEN EXIT DO
LOOP
_SNDCLOSE (soundHandle&)
TIMER(t1) OFF
TIMER(t1) FREE
END
DisplayPercent:
P = P + 1
IF P > 100 THEN RETURN
FOR L = 1 TO 4
PRINT CHR$(29); " "; CHR$(29);
NEXT
PRINT RIGHT$("000" + MID$(STR$(P), 2), 3); "%";
RETURN
捕获键盘输入和调用菜单时播放 .mp3 文件的另一个示例:子例程:(并在标题栏上显示百分比);
REM sample to display approx. percent in title bar while playing file
CLS
COLOR 15
PRINT "Playing..."
t1 = _FREETIMER
Filename$ = "music.mp3"
soundHandle& = _SNDOPEN(Filename$, "LEN") 'opens the sound file
IF soundHandle& = 0& THEN PRINT "Error opening file": END
x& = _SNDLEN(soundHandle&) 'get length of file in seconds
COLOR 14
PRINT "Length:"; x&; "seconds."
_TITLE "000%"
x! = x& / 100 'calculate percent
IF x! = 0! THEN x! = 1!
ON TIMER(t1, x!) GOSUB DisplayPercent
TIMER(t1) ON
_SNDPLAY soundHandle&
Playing = -1
DO
_LIMIT 50
x$ = INKEY$
IF x$ = CHR$(27) THEN EXIT DO
IF LEN(x$) THEN GOSUB menu
IF Playing THEN
x% = _SNDPLAYING(soundHandle&) 'check when file has finished playing
IF x% = 0 THEN
Playing = 0
COLOR 14
PRINT "Music playback finished.."
_SNDCLOSE (soundHandle&)
TIMER(t1) OFF
TIMER(t1) FREE
END IF
END IF
LOOP
IF Playing THEN
_SNDSTOP soundHandle&
_SNDCLOSE (soundHandle&)
TIMER(t1) OFF
TIMER(t1) FREE
END IF
COLOR 7
END
' trap input and do stuff here:
menu:
COLOR 15
IF LEN(x$) = 2 THEN
PRINT "You pressed: 0"; ASC(RIGHT$(x$, 1))
ELSE
PRINT "You pressed:"; ASC(x$)
END IF
RETURN
' display filename and percent on title bar
DisplayPercent:
P = P + 1
IF P > 100 THEN P = 101: RETURN ' check overflow
_TITLE "Playing " + Filename$ + " - " + RIGHT$("000" + MID$(STR$(P), 2), 3) + "%"
RETURN