1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import logging
import vlc
class PlaylistModel(QAbstractListModel):
def __init__(self, medialist, *args, **kwargs):
super(PlaylistModel, self).__init__(*args, **kwargs)
self.medialist = medialist
def data(self, index, role):
if role == Qt.DisplayRole:
return self.medialist.item_at_index(index.row()).get_mrl()
def rowCount(self, index):
return self.medialist.count()
class Playlist:
def __init__(self, window):
self.medialist = vlc.MediaList()
self.model = PlaylistModel(self.medialist)
self.window = window
window.player.set_media_list(self.medialist)
window.songListView.setModel(self.model)
window.songListView.selectionModel().selectionChanged.connect(self.playlistSelectionChanged)
window.addSongButton.pressed.connect(self.addSong)
def addSong(self):
path, _ = QFileDialog.getOpenFileName(self.window, "Open file", "", "mp3 Audio (*.mp3);FLAC audio (*.flac);All files (*.*)")
if path:
media = vlc.Media(path)
self.medialist.add_media(media)
self.model.layoutChanged.emit()
logging.debug(f"Added song: {path}")
def playlistSelectionChanged(self, ix):
i = ix.indexes()[0].row()
self.setCurrent(i)
#path = self.playlist.current.filePath
#self.player.set_media(path)
"""
self.abListModel.abList = self.internalState[path]
self.abListView.selectionModel().clearSelection()
self.abListModel.layoutChanged.emit()
self.aSlider.setValue(0)
self.bSlider.setValue(0)
"""
def setCurrent(self, index):
media = self.medialist.item_at_index(index)
if not media:
raise Exception(f"Invalid playlist index {index}")
self.medialist.set_media(media)
logging.debug(f"Selected song: {self.medialist.media().get_mrl()}")
|