Skip to content

Commit

Permalink
added extra file filters, fixed linux bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Charitra Agarwal committed Nov 22, 2020
1 parent baa7b80 commit 33706c9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions PyMediaPlayerAbstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import stagger
from PIL import Image
from PyQt5 import QtGui, QtCore
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QUrl, QDir
from PyQt5.QtMultimedia import *
from PyQt5.QtWidgets import QFileDialog

Expand Down Expand Up @@ -146,13 +146,19 @@ def playlist_selection_changed(self, ix):

def openfiles_button(self):
"""Adds songs from local files"""
filters = '*' + ' *'.join(supported_codecs) # required format should be like "*.mp3 *m4a"
filters = dict()
if len(supported_codecs) > 1: filters['All Audio files'] = '*' + ' *'.join(supported_codecs)
for ext in supported_codecs: filters[ext.replace('.', '').upper() + " Files"] = "*" + ext

paths, _ = QFileDialog.getOpenFileNames(self, "Open file", "", "Audio files ({0});".format(filters))
filter_text_list = []
for key in filters.keys(): filter_text_list.append(key + " ({})".format(filters[key]))

paths, _ = QFileDialog.getOpenFileNames(self, "Open file", "", ";;".join(filter_text_list))
if paths:
for path in paths:
self.playlist.addMedia(QMediaContent(QUrl.fromLocalFile(path)))
self.model.layoutChanged.emit()

# If player is in stopped state, play the first track
if self.player.state() != QMediaPlayer.PlayingState:
i = self.playlist.mediaCount() - len(paths)
Expand Down

0 comments on commit 33706c9

Please sign in to comment.