这是我目前拥有的
PRINT "Loading..."
soundHandle& = _SNDOPEN("Music.mp3") 'opens the sound file
_SNDPLAYFILE "Music.mp3", , .25 'plays the sound file
如果可能的话,我希望它是加载时上升的百分比
答案 0 :(得分: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
答案 1 :(得分: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
答案 2 :(得分:0)
另一个示例,在捕获键盘输入并调用菜单时播放.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