Ejemplo n.º 1
0
MediaPlayer::MediaPlayer(QObject *parent)
	: QObject(parent)
	, _playlist(nullptr)
	, _state(QMediaPlayer::StoppedState)
	, _localPlayer(new QtAV::AVPlayer(this))
	, _remotePlayer(nullptr)
	, _stopAfterCurrent(false)
{
	connect(_localPlayer, &QtAV::AVPlayer::stopped, this, [=]() {
		this->setState(QMediaPlayer::StoppedState);
	});

	connect(_localPlayer, &QtAV::AVPlayer::loaded, this, [=]() {
		_localPlayer->audio()->setVolume(Settings::instance()->volume());
		emit currentMediaChanged(_localPlayer->file());
		this->setState(QMediaPlayer::PlayingState);
	});

	connect(_localPlayer, &QtAV::AVPlayer::paused, this, [=](bool) {
		this->setState(QMediaPlayer::PausedState);
	});

	connect(_localPlayer, &QtAV::AVPlayer::positionChanged, this, [=](qint64 pos) {
		if (_state == QMediaPlayer::PlayingState) {
			emit positionChanged(pos, _localPlayer->duration());
		}
	});
	_localPlayer->audio()->setVolume(Settings::instance()->volume());

	connect(this, &MediaPlayer::currentMediaChanged, this, [=] (const QString &uri) {
		QWindow *w = QGuiApplication::topLevelWindows().first();
		TrackDAO t = SqlDatabase().selectTrackByURI(uri);
		if (t.artist().isEmpty()) {
			w->setTitle(t.title() + " - Miam Player");
		} else {
			w->setTitle(t.title() + " (" + t.artist() + ") - Miam Player");
		}
	});

	// Link core multimedia actions
	connect(this, &MediaPlayer::mediaStatusChanged, this, [=] (QMediaPlayer::MediaStatus status) {
		if (_state != QMediaPlayer::StoppedState && status == QMediaPlayer::EndOfMedia) {
			if (_stopAfterCurrent) {
				stop();
				_stopAfterCurrent = false;
			} else {
				skipForward();
			}
		}
	});
}
Ejemplo n.º 2
0
void tst_QGuiApplication::firstWindowTitle()
{
    int argc = 3;
    char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowtitle"), const_cast<char*>("User Title") };
    QGuiApplication app(argc, argv);
    QWindow window;
    window.setTitle("Application Title");
    window.show();
    QCOMPARE(window.title(), QString("User Title"));
}