使用 python-vlc 模块控制 VLC 播放器 [英] Control VLC player using python-vlc module
本文介绍了使用 python-vlc 模块控制 VLC 播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 python-vlc 模块控制 VLC 媒体播放器
Controlling the VLC media player using python-vlc module
我尝试了下面的代码,但出现错误:
I have tried the code below but am getting the error:
回溯(最近一次调用最后一次):文件",第 1 行,在
Traceback (most recent call last): File "", line 1, in
import vlc File "vlc.py", line 2, in <module>
# -*- coding: utf-8 -*-
AttributeError: 'module' 对象没有属性 'MediaPlayer'
AttributeError: 'module' object has no attribute 'MediaPlayer'
使用代码:
import vlc
media_player = vlc.MediaPlayer("path_to_your_song.mp3")
media_player.play()
我想让脚本运行并播放文件
I want the script to run and play the file
推荐答案
只需更改路径,就可以了..
Just change the path,your good to go..
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()
这篇关于使用 python-vlc 模块控制 VLC 播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文