在qb64中加载音频文件时可能加载条或百分比

问题描述 投票:2回答:3

这就是我现在拥有的

    PRINT "Loading..." 
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file

我想要它做的是在加载时上升的百分比,如果可能的话,

loading qb64
3个回答
2
投票

由于我不知道要加载的文件的大小,我可以提供的是:

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

0
投票

好的,我已经设法在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

0
投票

另一个播放.mp3文件的示例,同时捕获键盘输入和调用menu:子例程:(并在标题栏上显示百分比);

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
© www.soinside.com 2019 - 2024. All rights reserved.