Automating windows media player

后端 未结 3 757
-上瘾入骨i
-上瘾入骨i 2021-01-29 06:10

Any ideas about controling windows media player in Python? I found the following code on the net which runs fine but no audio is played. am using win7 64 bit machine

<         


        
3条回答
  •  星月不相逢
    2021-01-29 06:42

    Thought, it might help others who are still facing this issue. All you had to do is to call PlayItem() API after Play().

    from win32com.client import Dispatch
    from time import sleep
    
    mp = Dispatch("WMPlayer.OCX")
    tune = mp.newMedia("./plays.wav")
    mp.currentPlaylist.appendItem(tune)
    mp.controls.play()
    sleep(1)
    mp.controls.playItem(tune)
    raw_input("Press Enter to stop playing")
    mp.controls.stop()
    

提交回复
热议问题