数学建模社区-数学中国
标题:
Python-调用Bass音频库播放音乐
[打印本页]
作者:
檀俾九
时间:
2021-1-13 09:21
标题:
Python-调用Bass音频库播放音乐
#!/usr/bin/python
+ a: e( i% b% q7 r4 O4 U. U
# -*- coding: utf-8 -*-
) d% n1 \4 E( Y% T3 `
% n3 M: B& o( ]
from ctypes import windll
2 @# b `4 z0 y }) _- @
from os import getcwd
0 U) b5 c8 f2 m. L: z
from os.path import exists
& E' M0 U. P' ^' S+ ]6 [ F
4 o% {' t# ~( z) K3 B
if __name__ == '__main__':
# }- K' P6 d; w! S3 q
filepath = getcwd() + r"\bass.dll"
. L/ M+ b/ ~" V! W9 q* I) S
: V# r, a9 |# Z( ^" H1 }5 q. B$ {
if exists(filepath):
( x3 E/ d0 ?7 L
dll = windll.LoadLibrary(filepath)
& Q! }4 d( K! n- s: W3 r
dll.BASS_Init(-1, 44100, 0, None, None)
$ k, \9 g+ u; D+ Q0 v
handle = dll.BASS_StreamCreateFile(False, r"F:\KuGou\何晟铭&杜淳 - 爱的供养(男声合唱版).mp3".encode("gbk"), None, None, 0)
. E' n! ^" B+ \
dll.BASS_ChannelPlay(handle, False)
7 `1 F4 n, [/ V+ I+ J/ I( r
pos = dll.BASS_ChannelGetLength(handle, 0)
4 @* a% ]# ~+ @$ {9 a7 d
while dll.BASS_ChannelGetPosition(handle, 0) != pos:
2 r5 c) N$ o6 g& L5 @' \
pass
! s+ @6 j- x# _3 Y# s5 M1 Q
dll.BASS_Free()
% l9 F' w$ Q: d4 U/ I) D
复制代码
转发自
派生社区
Python交流群:1047602540
- v. f# n5 [+ Q! F5 j- i
0 h% f2 `4 t+ [% p9 P0 Y7 l
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5