subclass QMediaPlayer
This commit is contained in:
parent
89804aaccb
commit
c3945c51b8
26
components/MediaPlayer.py
Normal file
26
components/MediaPlayer.py
Normal file
@ -0,0 +1,26 @@
|
||||
from PyQt5.QtCore import QObject, QUrl
|
||||
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QMediaPlaylist
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
import sys
|
||||
|
||||
class MediaPlayer(QMediaPlayer):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# Connect mediaStatusChanged signal to our custom function
|
||||
self.mediaStatusChanged.connect(self.on_media_status_changed)
|
||||
|
||||
# def play(self, file_path):
|
||||
# media_content = QMediaContent(QUrl.fromLocalFile(file_path))
|
||||
# self.player.setMedia(media_content)
|
||||
# self.player.play()
|
||||
|
||||
def on_media_status_changed(self, status):
|
||||
if status == QMediaPlayer.MediaStatus.EndOfMedia:
|
||||
print("Song ended, triggering custom function!")
|
||||
self.on_song_ended()
|
||||
|
||||
def on_song_ended(self):
|
||||
# Your custom logic when the song ends
|
||||
print("Custom function executed after song ended!")
|
||||
|
||||
@ -66,6 +66,7 @@ from configparser import ConfigParser
|
||||
|
||||
class MusicTable(QTableView):
|
||||
playlistStatsSignal = pyqtSignal(str)
|
||||
loadMusicTableSignal = pyqtSignal()
|
||||
playPauseSignal = pyqtSignal()
|
||||
playSignal = pyqtSignal(str)
|
||||
enterKey = pyqtSignal()
|
||||
@ -698,7 +699,7 @@ class MusicTable(QTableView):
|
||||
# spawn new thread and calculate myself?
|
||||
total_time: int = 0 # total time of all songs in seconds
|
||||
for row_data in data:
|
||||
print(row_data)
|
||||
# print(row_data)
|
||||
# if "length" in fields:
|
||||
row_count += 1
|
||||
id, *rest_of_data = row_data
|
||||
@ -720,6 +721,7 @@ class MusicTable(QTableView):
|
||||
|
||||
self.model2.layoutChanged.emit() # emits a signal that the view should be updated
|
||||
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time}")
|
||||
self.loadMusicTableSignal.emit()
|
||||
self.connect_data_changed()
|
||||
self.connect_layout_changed()
|
||||
|
||||
|
||||
@ -11,3 +11,4 @@ from .PlaylistsPane import PlaylistsPane
|
||||
from .ExportPlaylistWindow import ExportPlaylistWindow
|
||||
from .QuestionBoxDetails import QuestionBoxDetails
|
||||
from .HeaderTags import HeaderTags
|
||||
from .MediaPlayer import MediaPlayer
|
||||
|
||||
16
main.py
16
main.py
@ -50,6 +50,7 @@ from utils import (
|
||||
set_album_art,
|
||||
)
|
||||
from components import (
|
||||
MediaPlayer,
|
||||
PreferencesWindow,
|
||||
AudioVisualizer,
|
||||
CreatePlaylistWindow,
|
||||
@ -168,8 +169,11 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
# widget bits
|
||||
self.album_art_scene: QGraphicsScene = QGraphicsScene()
|
||||
self.player: QMediaPlayer = QMediaPlayer() # Audio player object
|
||||
# self.player: QMediaPlayer = QMediaPlayer() # Audio player object
|
||||
self.player: QMediaPlayer = MediaPlayer()
|
||||
self.playlist: QMediaPlaylist = QMediaPlaylist()
|
||||
# set index on choose song
|
||||
# index is the model2's row number? i guess?
|
||||
self.probe: QAudioProbe = QAudioProbe() # Gets audio buffer data
|
||||
self.audio_visualizer: AudioVisualizer = AudioVisualizer(
|
||||
self.player, self.probe, self.PlotWidget
|
||||
@ -253,6 +257,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.tableView.playlistStatsSignal.connect(
|
||||
self.set_permanent_status_bar_message
|
||||
)
|
||||
self.tableView.loadMusicTableSignal.connect(self.load_media_playlist)
|
||||
self.tableView.load_music_table()
|
||||
|
||||
# playlistTreeView
|
||||
@ -363,6 +368,11 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
# | |
|
||||
# |____________________|
|
||||
|
||||
def load_media_playlist(self):
|
||||
self.proxymodel.row
|
||||
pass
|
||||
# self.playlist.
|
||||
|
||||
def setup_fonts(self):
|
||||
"""Initializes font sizes and behaviors for various UI components"""
|
||||
font: QFont = QFont()
|
||||
@ -421,7 +431,9 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def play_audio_file(self, filepath=None) -> None:
|
||||
"""
|
||||
Start playback of `tableView.current_song_filepath` & moves playback slider
|
||||
Start playback of filepath & moves playback slider
|
||||
|
||||
filepath default value = `tableView.current_song_filepath`
|
||||
"""
|
||||
if not filepath:
|
||||
filepath = self.tableView.get_selected_song_filepath()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user