/*!
  Use \a playlist as the source of images to be displayed in the viewer.
*/
void QMediaImageViewer::setPlaylist(QMediaPlaylist *playlist)
{
    Q_D(QMediaImageViewer);

    if (d->playlist) {
        disconnect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)),
                   this, SLOT(_q_playlistMediaChanged(QMediaContent)));
        disconnect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed()));

        QMediaObject::unbind(d->playlist);
    }

    d->playlist = playlist;

    if (d->playlist) {
        connect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)),
                this, SLOT(_q_playlistMediaChanged(QMediaContent)));
        connect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed()));

        QMediaObject::bind(d->playlist);

        setMedia(d->playlist->currentMedia());
    } else {
        setMedia(QMediaContent());
    }
}
Beispiel #2
0
Player::Player(  QWidget * parent, Qt::WindowFlags f)
    : QWidget(parent, f)
{
    m_current =NULL;
    last=NULL;

#ifdef REPEAT
    m_repeatCheck = false;
#endif
    m_mediaPlayer = new QMediaPlayer();
    connect(m_mediaPlayer,SIGNAL(stateChanged(QMediaPlayer::State)),this,SLOT(playerStatusChanged(QMediaPlayer::State)));
    connect(m_mediaPlayer,SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),this,SLOT(statusChanged(QMediaPlayer::MediaStatus)));

    connect(m_mediaPlayer,SIGNAL(currentMediaChanged(QMediaContent)),this,SLOT(sourceChanged(QMediaContent)));
    mypreference = Preference_data::getInstance();
    myPlaylist = Playlist::getInstance();
    m_listposition = -1;
    position = 0;
    selectedReadMode = mypreference->getSelectedReadMode();

    setupActions();

    //readSettings();
    setupUi();
    m_seekSlider->setMaximum(0);

}
void QMediaImageViewer::setMedia(const QMediaContent &media)
{
    Q_D(QMediaImageViewer);

    if (d->playlist && d->playlist->currentMedia() != media) {
        disconnect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)),
                   this, SLOT(_q_playlistMediaChanged(QMediaContent)));
        disconnect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed()));

        d->playlist = 0;
    }

    d->media = media;

    if (d->timer.isActive()) {
        d->pauseTime = 0;
        d->timer.stop();
        removePropertyWatch("elapsedTime");
        emit elapsedTimeChanged(0);
    }

    if (d->state != QMediaImageViewer::StoppedState)
        emit stateChanged(d->state = QMediaImageViewer::StoppedState);

    d->viewerControl->showMedia(d->media);

    emit mediaChanged(d->media);
}
void QMediaPlayerPrivate::connectPlaylist()
{
    Q_Q(QMediaPlayer);
    if (playlist) {
        QObject::connect(playlist, SIGNAL(currentMediaChanged(QMediaContent)),
                         q, SLOT(_q_updateMedia(QMediaContent)));
        QObject::connect(playlist, SIGNAL(destroyed()), q, SLOT(_q_playlistDestroyed()));
    }
}
Beispiel #5
0
/*!
  \internal
  If \a mediaObject is null or doesn't have an intrinsic playlist,
  internal local memory playlist source will be created.
*/
bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
{
    Q_D(QMediaPlaylist);

    if (mediaObject && mediaObject == d->mediaObject)
        return true;

    QMediaService *service = mediaObject
            ? mediaObject->service() : 0;

    QMediaPlaylistControl *newControl = 0;

    if (service)
        newControl = qobject_cast<QMediaPlaylistControl*>(service->requestControl(QMediaPlaylistControl_iid));

    if (!newControl)
        newControl = d->networkPlaylistControl;

    if (d->control != newControl) {
        int oldSize = 0;
        if (d->control) {
            QMediaPlaylistProvider *playlist = d->control->playlistProvider();
            oldSize = playlist->mediaCount();
            disconnect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
                    this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString)));

            disconnect(playlist, SIGNAL(mediaChanged(int,int)), this, SIGNAL(mediaChanged(int,int)));
            disconnect(playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SIGNAL(mediaAboutToBeInserted(int,int)));
            disconnect(playlist, SIGNAL(mediaInserted(int,int)), this, SIGNAL(mediaInserted(int,int)));
            disconnect(playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SIGNAL(mediaAboutToBeRemoved(int,int)));
            disconnect(playlist, SIGNAL(mediaRemoved(int,int)), this, SIGNAL(mediaRemoved(int,int)));

            disconnect(playlist, SIGNAL(loaded()), this, SIGNAL(loaded()));

            disconnect(d->control, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)),
                    this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
            disconnect(d->control, SIGNAL(currentIndexChanged(int)),
                    this, SIGNAL(currentIndexChanged(int)));
            disconnect(d->control, SIGNAL(currentMediaChanged(QMediaContent)),
                    this, SIGNAL(currentMediaChanged(QMediaContent)));

            if (d->mediaObject)
                d->mediaObject->service()->releaseControl(d->control);
        }
void ScreenTab::setModel(MediaTableModel *mediaModel)
{
    _currentMedia = NULL;
    emit currentMediaChanged(NULL);
    ui->mediaListTableView->setModel(mediaModel);
    if (mediaModel)
    {
        connect(ui->mediaListTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(mediaListSelectedChanded(QItemSelection,QItemSelection)));
    }
}
void QWmpPlaylistControl::currentItemChangeEvent(IDispatch *dispatch)
{
    IWMPMedia *media = 0;
    if (dispatch && dispatch->QueryInterface(
            __uuidof(IWMPMedia), reinterpret_cast<void **>(&media)) == S_OK) {
        int index = QWmpMetaData::value(media, QAutoBStr(L"PlaylistIndex")).toInt();

        emit currentIndexChanged(index);
        emit currentMediaChanged(m_playlist->media(index));
    }
}
void ScreenTab::mediaListSelectedChanded(const QItemSelection &selected, const QItemSelection &deselected)
{
    Q_UNUSED(deselected);
    ui->actionAddMedia->setEnabled(false);
    ui->actionAddExtension->setEnabled(false);
    ui->actionMoveMediaDown->setEnabled(false);
    ui->actionMoveMediaUp->setEnabled(false);
    ui->actionRemoveRow->setEnabled(false);
    ui->addMediaPushButton->setEnabled(false);
    ui->addExtensionPushButton->setEnabled(false);
    ui->removeRowPushButton->setEnabled(false);
    ui->moveRowDownPushButton->setEnabled(false);
    ui->moveRowUpPushButton->setEnabled(false);
    _currentMedia = NULL;

    QAbstractItemModel *mediaModel = ui->mediaListTableView->model();
    if (!mediaModel)
        return;
    ui->actionAddMedia->setEnabled(true);
    ui->addMediaPushButton->setEnabled(true);
    updateExtensions();

    QList<QModelIndex> selectedIndex = selected.indexes();
    if (selectedIndex.count() > 0)
    {
        ui->actionRemoveRow->setEnabled(true);
        ui->removeRowPushButton->setEnabled(true);
        QModelIndex index = selectedIndex[0];
        if (index.row() > 0)
        {
            ui->moveRowUpPushButton->setEnabled(true);
            ui->actionMoveMediaUp->setEnabled(true);
        } else
        {
            ui->moveRowUpPushButton->setEnabled(false);
            ui->actionMoveMediaUp->setEnabled(false);
        }
        if (index.row() < mediaModel->rowCount() - 1)
        {
            ui->moveRowDownPushButton->setEnabled(true);
            ui->actionMoveMediaDown->setEnabled(true);
        } else
        {
            ui->moveRowDownPushButton->setEnabled(false);
            ui->actionMoveMediaDown->setEnabled(false);
        }
        Media * currentObject = mediaModel->data(index, MediaTableModel::MediaPnt).value<Media *>();
        _currentMedia = currentObject;
    }
    emit currentMediaChanged(_currentMedia);

}
Beispiel #9
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();
			}
		}
	});
}
void ScreenTab::setScreen(Screen *screen)
{
    if (_screen == screen)
        return;
    if (_screen && _screen->parent() == this)
        _screen->deleteLater();
    _screen = screen;
    _currentMedia = NULL;
    _desktopMediaPlayer->setScreen(screen);
    emit currentMediaChanged(NULL);
    if (_screen)
    {
        if (!_screen->parent())
            _screen->setParent(this);
        setModel(_screen->getMediaModel());
        ui->randomMediaCheckBox->setChecked(_screen->getRandomEnabled());
        connect(_screen, SIGNAL(randomEnabledChanged(bool)), ui->randomMediaCheckBox, SLOT(setChecked(bool)));
        connect(ui->randomMediaCheckBox, SIGNAL(clicked(bool)), _screen, SLOT(setRandomEnabled(bool)));
//        ui->currentDisplaySpinBox->setValue(_screen->getNumberOfScreen());
//        connect(_screen, SIGNAL(numberOfScreenChanged(int)), ui->currentDisplaySpinBox, SLOT(setValue(int)));
//        connect(ui->currentDisplaySpinBox, SIGNAL(valueChanged(int)), _screen, SLOT(setNumberOfScreen(int)));
        //Установим имя таба
        if (!_screen->getName().isEmpty())
            setTabName(_screen->getName());
        connect(_screen, SIGNAL(nameChanged(QString)), this, SLOT(setTabName(QString)));
        connect(_screen, SIGNAL(dataToSaveChanged()), this, SIGNAL(dataChanged()));
        //Если это не реальный экран, то выключим ненужные кнопки
        if (_screen->getIsRealScreen())
        {
            ui->startPlayingPushButton->setEnabled(true);
            ui->actionStartStopPlaying->setEnabled(true);
//            ui->currentDisplayLabel->setEnabled(true);
//            ui->currentDisplaySpinBox->setEnabled(true);
            ui->addExtensionPushButton->setEnabled(true);
            ui->actionAddExtension->setEnabled(true);
        } else
        {
            ui->startPlayingPushButton->setEnabled(false);
            ui->actionStartStopPlaying->setEnabled(false);
//            ui->currentDisplayLabel->setEnabled(false);
//            ui->currentDisplaySpinBox->setEnabled(false);
            ui->addExtensionPushButton->setEnabled(false);
            ui->actionAddExtension->setEnabled(false);
        }
    }
    emit screenPointerChanged(_screen);
}
QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags):
    QMediaObject(*new QMediaPlayerPrivate,
                 parent,
                 playerService(flags))
{
    Q_D(QMediaPlayer);

    d->provider = QMediaServiceProvider::defaultServiceProvider();
    if (d->service == 0) {
        d->error = ServiceMissingError;
    } else {
        d->control = qobject_cast<QMediaPlayerControl*>(d->service->requestControl(QMediaPlayerControl_iid));
        d->networkAccessControl = qobject_cast<QMediaNetworkAccessControl*>(d->service->requestControl(QMediaNetworkAccessControl_iid));
        if (d->control != 0) {
            connect(d->control, SIGNAL(mediaChanged(QMediaContent)), SIGNAL(currentMediaChanged(QMediaContent)));
            connect(d->control, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(_q_stateChanged(QMediaPlayer::State)));
            connect(d->control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
                    SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus)));
            connect(d->control, SIGNAL(error(int,QString)), SLOT(_q_error(int,QString)));

            connect(d->control, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
            connect(d->control, SIGNAL(positionChanged(qint64)), SIGNAL(positionChanged(qint64)));
            connect(d->control, SIGNAL(audioAvailableChanged(bool)), SIGNAL(audioAvailableChanged(bool)));
            connect(d->control, SIGNAL(videoAvailableChanged(bool)), SIGNAL(videoAvailableChanged(bool)));
            connect(d->control, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int)));
            connect(d->control, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool)));
            connect(d->control, SIGNAL(seekableChanged(bool)), SIGNAL(seekableChanged(bool)));
            connect(d->control, SIGNAL(playbackRateChanged(qreal)), SIGNAL(playbackRateChanged(qreal)));
            connect(d->control, SIGNAL(bufferStatusChanged(int)), SIGNAL(bufferStatusChanged(int)));

            if (d->control->state() == PlayingState)
                addPropertyWatch("position");

            if (d->control->mediaStatus() == StalledMedia || d->control->mediaStatus() == BufferingMedia)
                addPropertyWatch("bufferStatus");
        }
        if (d->networkAccessControl != 0) {
            connect(d->networkAccessControl, SIGNAL(configurationChanged(QNetworkConfiguration)),
            this, SIGNAL(networkConfigurationChanged(QNetworkConfiguration)));
        }
    }
Beispiel #12
0
        connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
                this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString)));

        connect(playlist, SIGNAL(mediaChanged(int,int)), this, SIGNAL(mediaChanged(int,int)));
        connect(playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SIGNAL(mediaAboutToBeInserted(int,int)));
        connect(playlist, SIGNAL(mediaInserted(int,int)), this, SIGNAL(mediaInserted(int,int)));
        connect(playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SIGNAL(mediaAboutToBeRemoved(int,int)));
        connect(playlist, SIGNAL(mediaRemoved(int,int)), this, SIGNAL(mediaRemoved(int,int)));

        connect(playlist, SIGNAL(loaded()), this, SIGNAL(loaded()));

        connect(d->control, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)),
                this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
        connect(d->control, SIGNAL(currentIndexChanged(int)),
                this, SIGNAL(currentIndexChanged(int)));
        connect(d->control, SIGNAL(currentMediaChanged(QMediaContent)),
                this, SIGNAL(currentMediaChanged(QMediaContent)));

        if (oldSize)
            emit mediaRemoved(0, oldSize-1);

        if (playlist->mediaCount()) {
            emit mediaAboutToBeInserted(0,playlist->mediaCount()-1);
            emit mediaInserted(0,playlist->mediaCount()-1);
        }
    }

    d->mediaObject = mediaObject;

    return true;
}
Beispiel #13
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
     init_ui();
     setWindowTitle("CloudMusic");
     setWindowIcon(QIcon("images/cloudmusic.png"));
     setWindowFlags(Qt::FramelessWindowHint);
     setAttribute(Qt::WA_TranslucentBackground);//透明

     statue=3;
     connect(ui->play_BTN,SIGNAL(clicked(bool)),this,SLOT(music_play()));
     connect(ui->stop_BTN,SIGNAL(clicked(bool)),this,SLOT(music_stop()));
     connect(player,SIGNAL(durationChanged(qint64)),this,SLOT(song_time(qint64)));
     connect(player,SIGNAL(positionChanged(qint64)),this,SLOT(positionChanged(qint64)));
     connect(ui->time_Slider,SIGNAL(sliderMoved(int)),this,SLOT(positionMove(int)));
     connect(ui->load_action,SIGNAL(triggered(bool)),this,SLOT(load_local_music()));
     connect(ui->local_list,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(play_local_music()));
     connect(ui->cloud_list,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(play_cloud_music()));
     connect(ui->next_BTN,SIGNAL(clicked(bool)),this,SLOT(next_music()));
     connect(ui->exit_action,SIGNAL(triggered(bool)),this,SLOT(app_close()));
     connect(player,SIGNAL(currentMediaChanged(QMediaContent)),this,SLOT(music_changed()));
     connect(ui->next_page_BTN,SIGNAL(clicked(bool)),this,SLOT(next_page()));
     connect(ui->last_page_BTN,SIGNAL(clicked(bool)),this,SLOT(last_page()));
     connect(ui->refesh_BTN,SIGNAL(clicked(bool)),this,SLOT(list_refresh()));
     connect(ui->vote_btn,SIGNAL(clicked(bool)),this,SLOT(vote_song()));

     label_list.append(ui->list_name_1);
     label_list.append(ui->list_name_2);
     label_list.append(ui->list_name_3);
     label_list.append(ui->list_name_4);
     label_list.append(ui->list_name_5);
     label_list.append(ui->list_name_6);
     label_list.append(ui->list_name_7);
     label_list.append(ui->list_name_8);
     label_list.append(ui->list_name_9);

     BTN_list.append(ui->list_play_1);
     BTN_list.append(ui->list_play_2);
     BTN_list.append(ui->list_play_3);
     BTN_list.append(ui->list_play_4);
     BTN_list.append(ui->list_play_5);
     BTN_list.append(ui->list_play_6);
     BTN_list.append(ui->list_play_7);
     BTN_list.append(ui->list_play_8);
     BTN_list.append(ui->list_play_9);

     image_btns.append(ui->image_1);
     image_btns.append(ui->image_2);
     image_btns.append(ui->image_3);
     image_btns.append(ui->image_4);
     image_btns.append(ui->image_5);
     image_btns.append(ui->image_6);
     image_btns.append(ui->image_7);
     image_btns.append(ui->image_8);
     image_btns.append(ui->image_9);

     foreach(QPushButton *btn,image_btns)
     {
         connect(btn,SIGNAL(pressed()),this,SLOT(list_play_pressed()));
     }
Beispiel #14
0
 MainWindow::MainWindow()
 {
     //serv = new Server(*this);

     setWindowTitle("Music Player");

     menuFile = menuBar()->addMenu(tr("&File"));
     actionPlay = new QAction(QIcon(":images/play.png"),"Play", this);
     connect(actionPlay, SIGNAL(triggered()), this, SLOT(play()));
     menuFile->addAction(actionPlay);
     actionPause = new QAction(QIcon(":images/pause.png"),"Pause", this);
     connect(actionPause, SIGNAL(triggered()), this, SLOT(pause()));
     menuFile->addAction(actionPause);
     actionStop = new QAction(QIcon(":images/stop.png"),"Stop", this);
     connect(actionStop, SIGNAL(triggered()), this, SLOT(stop()));
     menuFile->addAction(actionStop);

     tbar = addToolBar(tr("Control Bar"));

     buttonPlay = new QToolButton;
     buttonPlay->setIcon(QIcon(":images/play.png"));
     connect(buttonPlay, SIGNAL(clicked()), this, SLOT(play()));
     buttonPause = new QToolButton;
     buttonPause->setIcon(QIcon(":images/pause.png"));
     connect(buttonPause, SIGNAL(clicked()), this, SLOT(pause()));
     buttonStop = new QToolButton;
     buttonStop->setIcon(QIcon(":images/stop.png"));
     connect(buttonStop, SIGNAL(clicked()), this, SLOT(stop()));
     buttonPrevious = new QToolButton;
     buttonPrevious->setIcon(QIcon(":images/prev.png"));
     connect(buttonPrevious, SIGNAL(clicked()), this, SLOT(previous()));
     buttonNext = new QToolButton;
     buttonNext->setIcon(QIcon(":images/next.png"));
     connect(buttonNext, SIGNAL(clicked()), this, SLOT(next()));
     buttonShuffle = new QToolButton;
     buttonShuffle->setIcon(QIcon(":images/shuffle.png"));
     connect(buttonShuffle, SIGNAL(clicked()), this, SLOT(shuffle()));
     buttonShuffleOff = new QToolButton;
     buttonShuffleOff->setIcon(QIcon(":images/shuffleoff.png"));
     connect(buttonShuffleOff, SIGNAL(clicked()), this, SLOT(shuffleOff()));
     buttonClearPl = new QToolButton;
     buttonClearPl->setIcon(QIcon(":images/clearpl.png"));
     connect(buttonClearPl, SIGNAL(clicked()), this, SLOT(clearPl()));
     QToolButton *addDir = new QToolButton;
     addDir->setIcon(QIcon(":images/addfolder.png"));
     connect(addDir, SIGNAL(clicked()), this, SLOT(addDir()));
     QToolButton *addFile = new QToolButton;
     addFile->setIcon(QIcon(":images/addfiles.png"));
     connect(addFile, SIGNAL(clicked()), this, SLOT(addFile()));
     QToolButton *runServer = new QToolButton;
     runServer->setIcon(QIcon(":images/server.png"));
     connect(runServer, SIGNAL(clicked()), this, SLOT(runServer()));

     progressSlider = new QSlider(Qt::Horizontal, this);
     volumeSlider = new QSlider(Qt::Horizontal, this);
     volumeLabel = new QLabel(this);
     durationLabel = new QLabel(this);
     nowPlayingLabel = new QLabel(this);
     volumeLabel->setText("Volume");
     tbar->addWidget(buttonPlay);
     tbar->addSeparator();
     tbar->addWidget(buttonPause);
     tbar->addSeparator();
     tbar->addWidget(buttonStop);
     tbar->addSeparator();
     tbar->addWidget(buttonPrevious);
     tbar->addSeparator();
     tbar->addWidget(buttonNext);
     tbar->addSeparator();
     tbar->addWidget(buttonShuffle);
     tbar->addSeparator();
     tbar->addWidget(buttonShuffleOff);
     tbar->addSeparator();
     tbar->addWidget(buttonClearPl);
     tbar->addSeparator();
     tbar->addWidget(addFile);
     tbar->addSeparator();
     tbar->addWidget(addDir);
     tbar->addSeparator();
     tbar->addWidget(runServer);
     tbar->addSeparator();
     tbar->addWidget(volumeLabel);
     tbar->addWidget(volumeSlider);
     tbar->addSeparator();
     barProgress = addToolBar(tr("Progress Bar"));
     barProgress->addWidget(progressSlider);
     barProgress->addSeparator();
     barProgress->addWidget(durationLabel);
     insertToolBarBreak(barProgress);
     statusBar()->addWidget(nowPlayingLabel);
     player = new QMediaPlayer;
     playlist = new QMediaPlaylist(player);
     playlist->setCurrentIndex(0);
     playlist->setPlaybackMode(QMediaPlaylist::Loop);
     tableWidget = new QListWidget(this);
     setCentralWidget(tableWidget);
     player->setPlaylist(playlist);
     player->setVolume(100);
     volumeSlider->setTickPosition(QSlider::TicksRight);
     volumeSlider->setValue(100);
     connect(volumeSlider, SIGNAL(valueChanged(int)), player, SLOT(setVolume(int)));
     connect(player,SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
     connect(player,SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(setDuration()));
     connect(player,SIGNAL(positionChanged(qint64)), this, SLOT(setDuration()));
     connect(progressSlider,SIGNAL(sliderMoved(int)), this, SLOT(setPosition(int)));
     connect(playlist, SIGNAL(currentMediaChanged(QMediaContent)), this, SLOT(checkAv()));
     connect(tableWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(objectClicked(QListWidgetItem*)));
     checkPlItems();

 }
Beispiel #15
0
void BridgeContact::setCurrentMedia( QString currentMedia )
{
    this->currentMedia = currentMedia;
    emit currentMediaChanged();
}
SmoozikSimplestClientWindow::SmoozikSimplestClientWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::SmoozikSimplestClientWindow)
{
    ui->setupUi(this);

    // Initialize SmoozikManager
    smoozikManager = new SmoozikManager(APIKEY, SECRET, SmoozikManager::XML, false, this);
    smoozikPlaylist = new SmoozikPlaylist;
    connect(smoozikManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetworkReply(QNetworkReply*)));

    // Initialize music directory
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    _dirName = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
#else
    _dirName = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
#endif

    // Initialize playlist filler
    ui->setupUi(this);
    smoozikPlaylistFillerThread = new QThread();
    smoozikPlaylistFiller = new SmoozikPlaylistFiller(smoozikPlaylist);
    smoozikPlaylistFiller->moveToThread(smoozikPlaylistFillerThread);
    connect(smoozikPlaylistFiller, SIGNAL(trackFound(QString,QString,QString,QString,uint)), this, SLOT(addTrackToPlaylist(QString,QString,QString,QString,uint)));
    connect(smoozikPlaylistFiller, SIGNAL(tracksRetrieved()), this, SIGNAL(tracksRetrieved()));
    connect(smoozikPlaylistFiller, SIGNAL(noTrackRetrieved()), this, SLOT(noTrackRetrievedMessage()));
    connect(smoozikPlaylistFiller, SIGNAL(maxPlaylistSizeReached()), this, SLOT(maxPlaylistSizeReachedMessage()));
    connect(smoozikPlaylistFillerThread, SIGNAL(started()), smoozikPlaylistFiller, SLOT(fillPlaylist()));
    connect(smoozikPlaylistFiller, SIGNAL(finished()), smoozikPlaylistFillerThread, SLOT(quit()), Qt::DirectConnection);

    // Initialize player
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    player = new Phonon::MediaObject(this);
    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(player, audioOutput);
    connect(player, SIGNAL(currentSourceChanged(Phonon::MediaSource)), this, SLOT(updateTrackLabels()));
    connect(player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(playerStateChanged()));
#else
    player = new QMediaPlayer(this);
    player->setPlaylist(new QMediaPlaylist(player));
    player->playlist()->setPlaybackMode(QMediaPlaylist::Sequential);
    connect(player, SIGNAL(currentMediaChanged(QMediaContent)), this, SLOT(updateTrackLabels()));
    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(playerStateChanged()));
#endif
    connect(ui->playButton, SIGNAL(clicked()), player, SLOT(play()));
    connect(ui->pauseButton, SIGNAL(clicked()), player, SLOT(pause()));
    connect(this, SIGNAL(currentTrackSet()), this, SLOT(updateTrackLabels()));
    connect(this, SIGNAL(nextTrackSet()), this, SLOT(updateTrackLabels()));

    // Initialize main state machine which controls what is displayed
    QStateMachine *mainStateMachine = new QStateMachine(this);
    QState *mainState = new QState(mainStateMachine);
    QState *loginState = new QState(mainState);
    QState *startPartyState = new QState(mainState);
    QState *connectedState = new QState(mainState);
    QState *retrieveTracksState = new QState(connectedState);
    QState *sendPlaylistState = new QState(connectedState);
    QState *getTopTracksState = new QState(connectedState);
    QState *partyState = new QState(connectedState);
    QState *waitingState = new QState(partyState);
    QState *sendCurrentTrackState = new QState(partyState);
    QState *sendNextTrackState = new QState(partyState);

    QStateMachine *playerStateMachine = new QStateMachine(this);
    QState *playerState = new QState(playerStateMachine);
    QState *playingState = new QState(playerState);
    QState *pausedState = new QState(playerState);

    // Define state initial states and transitions
    mainStateMachine->setInitialState(mainState);
    mainState->setInitialState(loginState);
    connectedState->setInitialState(retrieveTracksState);
    partyState->setInitialState(waitingState);
    playerStateMachine->setInitialState(playerState);
    playerState->setInitialState(pausedState);

    mainState->addTransition(this, SIGNAL(disconnected()), loginState);
    loginState->addTransition(this, SIGNAL(loggedIn()), startPartyState);
    startPartyState->addTransition(this, SIGNAL(partyStarted()), connectedState);
    connectedState->addTransition(ui->changePlaylistButton, SIGNAL(clicked()), retrieveTracksState);
    retrieveTracksState->addTransition(this, SIGNAL(tracksRetrieved()), sendPlaylistState);
    sendPlaylistState->addTransition(this, SIGNAL(playlistSent()), getTopTracksState);
    getTopTracksState->addTransition(this, SIGNAL(currentTrackSet()), sendCurrentTrackState);
    sendCurrentTrackState->addTransition(this, SIGNAL(currentTrackSent()), getTopTracksState);
    getTopTracksState->addTransition(this, SIGNAL(nextTrackSet()), sendNextTrackState);
    sendNextTrackState->addTransition(this, SIGNAL(nextTrackSent()), waitingState);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    waitingState->addTransition(player, SIGNAL(currentSourceChanged(Phonon::MediaSource)), sendCurrentTrackState);
#else
    waitingState->addTransition(player, SIGNAL(currentMediaChanged(QMediaContent)), sendCurrentTrackState);
#endif

    playerState->addTransition(this, SIGNAL(playing()), playingState);
    playerState->addTransition(this, SIGNAL(paused()), pausedState);

    // Define state properties
    loginState->assignProperty(this, "state", Login);
    loginState->assignProperty(ui->stackedWidget, "currentIndex", ui->stackedWidget->indexOf(ui->loginPage));
    loginState->assignProperty(ui->loginButton, "enabled", true);
    loginState->assignProperty(ui->disconnectButton, "visible", false);
    loginState->assignProperty(ui->changePlaylistButton, "visible", false);
    loginState->assignProperty(ui->usernameLineEdit, "enabled", true);
    loginState->assignProperty(ui->passwordLineEdit, "enabled", true);
    loginState->assignProperty(ui->loginStateLabel, "text", QString());

    startPartyState->assignProperty(this, "state", StartParty);
    startPartyState->assignProperty(ui->loginStateLabel, "text", tr("Starting party..."));
    startPartyState->assignProperty(ui->disconnectButton, "visible", false);
    startPartyState->assignProperty(ui->changePlaylistButton, "visible", false);

    connectedState->assignProperty(ui->disconnectButton, "visible", true);

    retrieveTracksState->assignProperty(ui->stackedWidget, "currentIndex", ui->stackedWidget->indexOf(ui->loadingPage));
    retrieveTracksState->assignProperty(ui->loginStateLabel, "text", tr("Connected"));
    retrieveTracksState->assignProperty(ui->loadingLabel, "text", tr("Retrieving tracks..."));
    retrieveTracksState->assignProperty(ui->changePlaylistButton, "visible", false);

    sendPlaylistState->assignProperty(this, "state", SendPlaylist);
    sendPlaylistState->assignProperty(ui->loadingLabel, "text", tr("Sending playlist..."));
    sendPlaylistState->assignProperty(ui->changePlaylistButton, "visible", true);

    getTopTracksState->assignProperty(this, "state", GetTopTracks);
    getTopTracksState->assignProperty(ui->loadingLabel, "text", tr("Get top tracks..."));
    getTopTracksState->assignProperty(ui->nextButton, "enabled", false);
    getTopTracksState->assignProperty(ui->changePlaylistButton, "visible", true);

    partyState->assignProperty(ui->stackedWidget, "currentIndex", ui->stackedWidget->indexOf(ui->playerPage));
    partyState->assignProperty(ui->changePlaylistButton, "visible", true);

    sendCurrentTrackState->assignProperty(this, "state", SendCurrentTrack);
    sendCurrentTrackState->assignProperty(ui->nextButton, "enabled", false);

    sendNextTrackState->assignProperty(this, "state", SendNextTrack);
    sendNextTrackState->assignProperty(ui->nextButton, "enabled", false);

    waitingState->assignProperty(ui->nextButton, "enabled", true);

    playingState->assignProperty(ui->playButton, "visible", false);
    playingState->assignProperty(ui->pauseButton, "visible", true);

    pausedState->assignProperty(ui->playButton, "visible", true);
    pausedState->assignProperty(ui->pauseButton, "visible", false);

    // Connect states and actions
    connect(startPartyState, SIGNAL(entered()), this, SLOT(startParty()));
    connect(retrieveTracksState, SIGNAL(entered()), this, SLOT(retrieveTracksDialog()));
    connect(sendPlaylistState, SIGNAL(entered()), this, SLOT(sendPlaylist()));
    connect(getTopTracksState, SIGNAL(entered()), this, SLOT(getTopTracks()));
    connect(sendCurrentTrackState, SIGNAL(entered()), this, SLOT(sendCurrentTrack()));
    connect(sendNextTrackState, SIGNAL(entered()), this, SLOT(sendNextTrack()));

    // Connect gui and actions
    connect(ui->usernameLineEdit, SIGNAL(returnPressed()), this, SLOT(submitLogin()));
    connect(ui->passwordLineEdit, SIGNAL(returnPressed()), this, SLOT(submitLogin()));
    connect(ui->loginButton, SIGNAL(clicked()), this, SLOT(submitLogin()));
    connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(nextTrack()));
    connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));

    // Start state machine
    mainStateMachine->start();
    playerStateMachine->start();
}