无法在wxpython中获得音乐的长度

问题描述 投票:0回答:1

我正在尝试使用wxpython,mPlayerCtrl构建一个音乐播放器。但我有一个问题,即获得添加音乐的长度。我试过了:

self.mplayer.Length()

当我使用.Length()时给出错误

AttributeError:'MplayerCtrl'对象没有属性'Length'

self.mplayer.length()

当我使用.length()时给出错误

TypeError:'NoneType'对象不可调用

t_len = self.mplayer.GetTimeLength()
self.playbackSlider.SetRange(0, t_len)

这给出了一个错误

TypeError:Slider.SetRange():参数2具有意外类型'NoneType'

我的代码如下

if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath()
        self.currentFolder = os.path.dirname(path[0])
        trackPath = '"%s"' % path.replace("\\", "/")
        self.mplayer.Loadfile(trackPath)
        t_len = self.mplayer.GetTimeLength()
        self.playbackSlider.SetRange(0, t_len)
        self.playbackTimer.Start(100.0)
python python-3.x python-2.7 wxpython mplayer
1个回答
0
投票

您可能需要调用GetProperty才能获得媒体长度:

length = self.mplayer.GetProperty('length')

请参阅here属性的完整列表

© www.soinside.com 2019 - 2024. All rights reserved.