只是改变路径,你很好去..
from vlc import Instance
import time
import os
class VLC:
def __init__(self):
self.Player = Instance('--loop')
def addPlaylist(self):
self.mediaList = self.Player.media_list_new()
path = r"C:\Users\dell5567\Desktop\engsong"
songs = os.listdir(path)
for s in songs:
self.mediaList.add_media(self.Player.media_new(os.path.join(path,s)))
self.listPlayer = self.Player.media_list_player_new()
self.listPlayer.set_media_list(self.mediaList)
def play(self):
self.listPlayer.play()
def next(self):
self.listPlayer.next()
def pause(self):
self.listPlayer.pause()
def previous(self):
self.listPlayer.previous()
def stop(self):
self.listPlayer.stop()
创建一个对象
player = VLC()
添加播放列表
player.addPlaylist()
播放歌曲
player.play()
time.sleep(9)
播放下一首歌曲
player.next()
time.sleep(9)
暂停歌曲
player.pause()
time.sleep(9)
继续听歌
player.play()
time.sleep(9)
上一首歌
player.previous()
time.sleep(9)
停止歌曲
player.stop()