如何在python中使用vlc.py模块播放常规音频CD和/或DVD?

时间:2016-11-11 19:27:12

标签: python vlc

我使用python和Tkinter创建了一个可在我的汽车中使用的媒体播放器,同时使用vlc python bindings(vlc.py)播放音乐和视频。我已经弄清楚如何播放mp3和mp4文件,但我无法弄清楚如何播放CD和DVD。任何帮助将不胜感激。

适用于播放mp3的代码

import vlc
instance = vlc.Instance()
player = instance.media_player_new()
media = instance.media_new('path/to/mp3')
player.set_media(media)
player.play()

1 个答案:

答案 0 :(得分:1)

解决方案在VideoLAN论坛上找到: https://forum.videolan.org/viewtopic.php?f=32&t=136746&p=451666#p451666

播放单曲:

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "EnumerableString"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private m_characters As Collection

Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
    Set NewEnum = m_characters.[_NewEnum]
End Property

Public Property Let Value(ByVal newValue As String)
    Dim pos As Integer
    Set m_characters = New Collection
    For pos = 1 To Len(newValue)
        m_characters.Add Mid$(newValue, pos, 1)
    Next pos
End Property

Public Function Length() As Long
    Length = m_characters.Count
End Function

Public Function Item(ByVal index As Variant) As String
Attribute Item.VB_UserMemId = 0
    Item = m_characters(index)
End Function

Private Sub Class_Initialize()
    Set m_characters = New Collection
End Sub

播放整张CD:

import vlc

Player = vlc.MediaPlayer("cdda:///O:/", ":cdda-track=3")
Player.play()

while True:
    pass

其中instance = vlc.Instance() player = instance.media_player_new() medialist = instance.media_list_new() listplayer = instance.media_list_player_new() listplayer.set_media_player(player) for i in (range(1,10)): # the second value for range() can be set without problem also higher track = instance.media_new("cdda:///O:/", (":cdda-track=" + str(i))) medialist.add_media(track) listplayer.set_media_list(medialist) listplayer.play() while True: pass 是驱动器号。