Polish the QtWidgets/Player example.
Point the file dialog to the Movies folder. Add command proper command line handling. Change the logic to use QUrl everywhere. Change-Id: I1e54e600187153f52a55e3a381a24e4f2eeda3ab Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
@@ -167,7 +167,7 @@ Player::Player(QWidget *parent)
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
if (!player->isAvailable()) {
|
||||
if (!isPlayerAvailable()) {
|
||||
QMessageBox::warning(this, tr("Service not available"),
|
||||
tr("The QMediaPlayer object does not have a valid service.\n"\
|
||||
"Please check the media service plugins are installed."));
|
||||
@@ -182,38 +182,47 @@ Player::Player(QWidget *parent)
|
||||
}
|
||||
|
||||
metaDataChanged();
|
||||
|
||||
QStringList arguments = qApp->arguments();
|
||||
arguments.removeAt(0);
|
||||
addToPlaylist(arguments);
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
{
|
||||
}
|
||||
|
||||
void Player::open()
|
||||
bool Player::isPlayerAvailable() const
|
||||
{
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Files"));
|
||||
addToPlaylist(fileNames);
|
||||
return player->isAvailable();
|
||||
}
|
||||
|
||||
void Player::addToPlaylist(const QStringList& fileNames)
|
||||
void Player::open()
|
||||
{
|
||||
foreach (QString const &argument, fileNames) {
|
||||
QFileInfo fileInfo(argument);
|
||||
if (fileInfo.exists()) {
|
||||
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||
if (fileInfo.suffix().toLower() == QLatin1String("m3u")) {
|
||||
playlist->load(url);
|
||||
} else
|
||||
playlist->addMedia(url);
|
||||
} else {
|
||||
QUrl url(argument);
|
||||
if (url.isValid()) {
|
||||
playlist->addMedia(url);
|
||||
}
|
||||
}
|
||||
QFileDialog fileDialog(this);
|
||||
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
fileDialog.setWindowTitle(tr("Open Files"));
|
||||
QStringList supportedMimeTypes = player->supportedMimeTypes();
|
||||
if (!supportedMimeTypes.isEmpty()) {
|
||||
supportedMimeTypes.append("audio/x-m3u"); // MP3 playlists
|
||||
fileDialog.setMimeTypeFilters(supportedMimeTypes);
|
||||
}
|
||||
fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).value(0, QDir::homePath()));
|
||||
if (fileDialog.exec() == QDialog::Accepted)
|
||||
addToPlaylist(fileDialog.selectedUrls());
|
||||
}
|
||||
|
||||
static bool isPlaylist(const QUrl &url) // Check for ".m3u" playlists.
|
||||
{
|
||||
if (!url.isLocalFile())
|
||||
return false;
|
||||
const QFileInfo fileInfo(url.toLocalFile());
|
||||
return fileInfo.exists() && !fileInfo.suffix().compare(QLatin1String("m3u"), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
void Player::addToPlaylist(const QList<QUrl> urls)
|
||||
{
|
||||
foreach (const QUrl &url, urls) {
|
||||
if (isPlaylist(url))
|
||||
playlist->load(url);
|
||||
else
|
||||
playlist->addMedia(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user