数学建模社区-数学中国

标题: Python-调用Bass音频库播放音乐 [打印本页]

作者: 檀俾九    时间: 2021-1-13 09:21
标题: Python-调用Bass音频库播放音乐
  1. #!/usr/bin/python7 b& D( ]: E' u" z* y2 U3 w- A- C
  2. # -*- coding: utf-8 -*-3 ?5 H. t2 j" e9 e+ G9 I

  3. ( h* S% F4 L1 y# f' g5 F
  4. from ctypes import windll
    * |6 I4 \' B9 O+ T% ^/ o
  5. from os import getcwd
    / {! Q# J! q$ p' N/ Z
  6. from os.path import exists9 b2 |* h' J- T
  7.   r/ |3 |1 V, e6 }# m4 G. Q: a
  8. if __name__ == '__main__':4 J, X0 b& r7 n; Z$ Z
  9.     filepath = getcwd() + r"\bass.dll"5 H, w, l+ W/ {
  10. " R% @+ p0 C) V- N+ _  \4 y1 k
  11.     if exists(filepath):
    6 c' W+ A& c& B; u; O
  12.         dll = windll.LoadLibrary(filepath); z* B: l- A# l7 N1 Z: a, }
  13.         dll.BASS_Init(-1, 44100, 0, None, None)
    ) {% p& i- Q: k0 S6 d* s$ L) F8 a
  14.         handle = dll.BASS_StreamCreateFile(False, r"F:\KuGou\何晟铭&杜淳 - 爱的供养(男声合唱版).mp3".encode("gbk"), None, None, 0)
    2 w; I! [5 ?: }. S
  15.         dll.BASS_ChannelPlay(handle, False)- Y5 A/ f% s) D6 q# `
  16.         pos = dll.BASS_ChannelGetLength(handle, 0)
    : j2 L; c' u. h3 X) R% m) W
  17.         while dll.BASS_ChannelGetPosition(handle, 0) != pos:; Y/ o1 k, u1 i' v
  18.             pass1 U1 L$ z1 ]& a6 t& O5 u
  19.         dll.BASS_Free()' f8 g3 `) u+ Q4 z. C* s" y; {
复制代码
转发自派生社区
Python交流群:1047602540
' w, |* i3 C! N: c
6 z' ^5 n' I' r





欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5