数学建模社区-数学中国
标题:
Python-调用Bass音频库播放音乐
[打印本页]
作者:
檀俾九
时间:
2021-1-13 09:21
标题:
Python-调用Bass音频库播放音乐
#!/usr/bin/python
# d+ y- o: Y" N* l B9 z' a4 O
# -*- coding: utf-8 -*-
/ d. [' e1 ?1 O2 E9 @% I- G
8 {& `5 X) c* O* j1 q% l7 O9 e; R0 W
from ctypes import windll
+ z. Q' U1 s* a. C E7 Y
from os import getcwd
" D3 i$ j% ]- D
from os.path import exists
4 z: E: ~& _" P1 i7 N3 ]
& u' e+ G; {. W S4 c3 Y; i3 e7 D% p
if __name__ == '__main__':
' y7 [. K, y+ i8 X h, T9 r
filepath = getcwd() + r"\bass.dll"
% E! M) E" S- O) f9 G/ C
" x3 f% E( ? |& w5 L
if exists(filepath):
; i% k8 A0 R. @3 Z
dll = windll.LoadLibrary(filepath)
- I; Q( Y# [" b* v" f7 x' l
dll.BASS_Init(-1, 44100, 0, None, None)
6 n. `6 R0 q# ?2 q5 Z" Y
handle = dll.BASS_StreamCreateFile(False, r"F:\KuGou\何晟铭&杜淳 - 爱的供养(男声合唱版).mp3".encode("gbk"), None, None, 0)
4 _# A& e8 H9 r' q. _" b; e- {
dll.BASS_ChannelPlay(handle, False)
0 C% f4 p: l' I) M; H3 q8 |
pos = dll.BASS_ChannelGetLength(handle, 0)
- \. c6 G! v7 {, g# b
while dll.BASS_ChannelGetPosition(handle, 0) != pos:
+ P2 J7 M/ a' `, H( v
pass
9 T; d$ a8 j, A$ A" i, s
dll.BASS_Free()
! d/ Q3 |4 k9 I0 f: E$ G
复制代码
转发自
派生社区
Python交流群:1047602540
: U4 g0 m: c$ \4 [/ B( ~, A
7 U! X$ g, m6 `0 M# G
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5