Esempio n. 1
0
MediaPlayer2Player::MediaPlayer2Player(QObject* parent) : QDBusAbstractAdaptor(parent)
{
    connect(Dragon::engine(), SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
    connect(Dragon::engine(), SIGNAL(currentSourceChanged(Phonon::MediaSource)), this, SLOT(currentSourceChanged()));
    connect(Dragon::engine(), SIGNAL(metaDataChanged()), this, SLOT(emitMetadataChange()));
    connect(Dragon::engine(), SIGNAL(stateUpdated(Phonon::State,Phonon::State)), this, SLOT(stateUpdated()));
    connect(Dragon::engine(), SIGNAL(totalTimeChanged(qint64)), this, SLOT(emitMetadataChange()));
    connect(Dragon::engine(), SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
    connect(Dragon::engine(), SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged()));
}
Esempio n. 2
0
PlaybackWidget::PlaybackWidget(DataStore *dataStore, QWidget *parent):
  QWidget(parent), dataStore(dataStore), currentPlaybackState(PLAYING)
{
  audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
  mediaObject = new Phonon::MediaObject(this);
  createActions();
  setupUi();

  mediaObject->setTickInterval(1000);
  connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
  connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
    this, SLOT(stateChanged(Phonon::State, Phonon::State)));
  connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
    this, SLOT(sourceChanged(Phonon::MediaSource)));
  connect(mediaObject, SIGNAL(finished()), this, SLOT(playNextSong()));
  connect(
    mediaObject,
    SIGNAL(metaDataChanged()),
    this,
    SLOT(metaDataChanged()));
  connect(
    dataStore,
    SIGNAL(manualSongChange(Phonon::MediaSource)),
    this,
    SLOT(setNewSource(Phonon::MediaSource)));

  connect(
    dataStore,
    SIGNAL(eventEnded()),
    this,
    SLOT(clearWidget()));

  connect(
    dataStore,
    SIGNAL(eventCreated()),
    this,
    SLOT(enablePlayback()));

  connect(
    dataStore,
    SIGNAL(eventEnded()),
    this,
    SLOT(disablePlayback()));

  connect(
    dataStore,
    SIGNAL(activePlaylistModified()),
    this,
    SLOT(handlePlaylistChange()));

  Phonon::createPath(mediaObject, audioOutput);
  dataStore->isCurrentlyHosting() ? setEnabled(true) : setEnabled(false);
  playNextSong();
}
Esempio n. 3
0
MediaPlayer2Player::MediaPlayer2Player(QObject* parent)
    : QDBusAbstractAdaptor(parent)
    , m_player(JuK::JuKInstance()->playerManager())
{
    connect(m_player, SIGNAL(signalItemChanged(FileHandle)), this, SLOT(currentSourceChanged()));
    connect(m_player, SIGNAL(signalPause()), this, SLOT(stateUpdated()));
    connect(m_player, SIGNAL(signalStop()), this, SLOT(stateUpdated()));
    connect(m_player, SIGNAL(totalTimeChanged(int)), this, SLOT(totalTimeChanged()));
    connect(m_player, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
    connect(m_player, SIGNAL(volumeChanged(float)), this, SLOT(volumeChanged(float)));
    connect(m_player, SIGNAL(seeked(int)), this, SLOT(seeked(int)));
}
Esempio n. 4
0
disqteca::disqteca(QWidget *parent) : QMainWindow(parent), ui(new Ui::disqteca) {

    audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory, this);
    videoWidget = new Phonon::VideoWidget();
    videoWidget->setGeometry(0, 0, 1920, 1080);
    videoWidget->setMinimumWidth(320);
    videoWidget->setMinimumHeight(240);

    mediaObject = new Phonon::MediaObject(this);
    metaInformationResolver = new Phonon::MediaObject(this);

    mediaObject->setTickInterval(1000);

    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
    connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(stateChanged(Phonon::State,Phonon::State)));
    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(sourceChanged(Phonon::MediaSource)));
    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));

    // Nunca referenciar nenhum objeto da UI antes dessa linha
    ui->setupUi(this);

    // Liga objetos de busca, volume e os widgets de áudio e video
    ui->seekSlider->setMediaObject(mediaObject);
    ui->volumeSlider->setAudioOutput(audioOutput);
    Phonon::createPath(mediaObject, audioOutput);
    Phonon::createPath(mediaObject, videoWidget);

    DivisorVideoMixteca = new QSplitter;
    DivisorVideoMixteca->addWidget(videoWidget);
    DivisorVideoMixteca->addWidget(ui->Mixteca);

    QVBoxLayout *DivisorCentral = new QVBoxLayout;
    DivisorCentral->addWidget(DivisorVideoMixteca);
    DivisorCentral->addWidget(ui->controlesWidget);

    QWidget *Central = new QWidget;
    Central->setLayout(DivisorCentral);

    setCentralWidget(Central);

    QStringList Cabecalhos;
    Cabecalhos << tr("Titulo") << tr("Artista") << tr("Disco") << tr("Ano");

    ui->Mixteca->setHorizontalHeaderLabels(Cabecalhos);
    ui->sairAction->setShortcuts(QKeySequence::Quit);

}
Esempio n. 5
0
void AudioPlayer::slotFinished()
{
    if (!bufferingTrack_)
        return;
    if (bufferingTrack_->isCueTrack() && bufferingTrack_->location == playingTrack_->location &&
        bufferingTrack_->metadata["track"].toInt() == playingTrack_->metadata["track"].toInt() + 1) {
        currentSourceChanged();
        return;
    }
    if (queue_.peeked())
        queue_.unpeek();
    next();
}
Esempio n. 6
0
void MediaObject::setSource(const Phonon::MediaSource &source)
{
    m_nextSourceReadyToStart = false;
    m_prefinishMarkSent = false;
    m_aboutToFinishSent = false;

    m_oldHasVideo = currentGraph()->hasVideo();
    setState(Phonon::LoadingState);
    //After loading we go into stopped state
    m_nextState = Phonon::StoppedState;
    catchComError(currentGraph()->loadSource(source));
    emit currentSourceChanged(source);
}
        void MediaObject::setSource(const Phonon::MediaSource &source)
        {
            if (m_state == Phonon::PlayingState)
            {
                setError(Phonon::NormalError, QLatin1String("source changed while playing"));
                stop();
            }

            m_source = source;
            m_hasSource = true;
            m_sourceIsValid = false;

            emit currentSourceChanged(source);

            if (source.type() == Phonon::MediaSource::LocalFile) {
                if (!openWaveFile(source.fileName())) {
                  setError(Phonon::FatalError, QLatin1String("cannot open media file"));
                  return ;
                }
            } else if (source.type() == Phonon::MediaSource::Stream) {
                if (m_stream)
                   delete m_stream;
                m_stream = new IOWrapper(this, source);
                m_mediaSize = m_stream->size();
            } else if (source.type() == Phonon::MediaSource::Url) {
                if (!openWaveFile(source.url().toLocalFile())) {
                    setError(Phonon::FatalError, QLatin1String("cannot open media file"));
                    return ;
                }
            } else {
                setError(Phonon::FatalError, QLatin1String("type of source not supported"));
                return ;
            }
            setState(Phonon::LoadingState);

            if (!readHeader())
                setError(Phonon::FatalError, QLatin1String("invalid header"));
            else if (!getWaveOutDevice())
                setError(Phonon::FatalError, QLatin1String("No waveOut device available"));
            else if (!fillBuffers())
                setError(Phonon::FatalError, QLatin1String("no data for buffering"));
            else if (!prepareBuffers())
                setError(Phonon::FatalError, QLatin1String("cannot prepare buffers"));
            else
                m_sourceIsValid = true;

            if (m_sourceIsValid)
                setState(Phonon::StoppedState);
        }
Esempio n. 8
0
StatesValidator::StatesValidator(MediaObject *parent)
    : QObject(parent)
    , m_mediaObject(parent)
    , m_prevState(Phonon::ErrorState)
    , m_sourceQueued(false)
    , m_aboutToFinishEmitted(false)
    , m_aboutToFinishBeforeSeek(false)
    , m_aboutToFinishPos(-1)
{
    connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(validateStateChange(Phonon::State,Phonon::State)));
    connect(m_mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(validateSourceChange()));
    connect(m_mediaObject, SIGNAL(tick(qint64)), this, SLOT(validateTick(qint64)));
    connect(m_mediaObject, SIGNAL(aboutToFinish()), this, SLOT(validateAboutToFinish()));
    connect(m_mediaObject, SIGNAL(finished()), this, SLOT(validateFinished()));
    connect(m_mediaObject, SIGNAL(bufferStatus(int)), this, SLOT(validateBufferStatus()));
}
Esempio n. 9
0
/*
 * !reimp
 */
void MediaObject::setSource(const MediaSource &source)
{
    QMultiMap<QString, QString> ret;

    ret.insert(QLatin1String("ARTIST"), "Nokia Dude");
    ret.insert(QLatin1String("ALBUM"), "Sound of silence");
    ret.insert(QLatin1String("DATE"), "2009");

    m_error = Phonon::NoError;
    setState(Phonon::LoadingState);

    m_source = source;
    currentPos = 0;

    if((source.fileName().contains(".avi")) ||
       (source.fileName().contains(".mp4"))) {
        m_hasVideo = true;
        emit hasVideoChanged(m_hasVideo);
    }
    if(source.fileName().contains(".wav")) {
        QFile file(source.fileName());
        if (file.open(QIODevice::ReadOnly)) {
            int len = file.read((char*)&header, sizeof(CombinedHeader));
            if(len == sizeof(CombinedHeader)) {
                if(memcmp(&header.riff.descriptor.id, riffId, 4) != 0) {
                    // Not a valid wav file, to satisfy unit test for mediaobject
                    m_error = Phonon::FatalError;
                    //m_state = Phonon::ErrorState;
                    m_errorString = "Invalid wav file";
                    setState(Phonon::ErrorState);
                    file.close();
                    return;
                }
            }
            file.close();
        }
    }
    emit metaDataChanged(ret);
    emit currentSourceChanged(source);
    emit totalTimeChanged(m_totalTime);

    setState(Phonon::StoppedState);
}
Esempio n. 10
0
	void SourceObject::HandleElementMsg (GstMessage *msg)
	{
#if GST_VERSION_MAJOR < 1
		const auto msgStruct = gst_message_get_structure (msg);

		if (gst_structure_has_name (msgStruct, "playbin2-stream-changed"))
		{
			gchar *uri = nullptr;
			g_object_get (Dec_, "uri", &uri, nullptr);
			qDebug () << Q_FUNC_INFO << uri;
			g_free (uri);

			setActualSource (CurrentSource_);
			emit currentSourceChanged (CurrentSource_);
		}
#else
		Q_UNUSED (msg)
#endif
	}
Esempio n. 11
0
        void MediaObject::switchToNextSource()
        {
            m_prefinishMarkSent = false;
            m_aboutToFinishSent = false;
            m_nextSourceReadyToStart = false;

            m_oldHasVideo = currentGraph()->hasVideo();

            qSwap(m_graphs[0], m_graphs[1]); //swap the graphs

            if (m_transitionTime >= 0)
                m_graphs[1]->stop(); //make sure we stop the previous graph

            if (currentGraph()->mediaSource().type() != Phonon::MediaSource::Invalid &&
                catchComError(currentGraph()->renderResult())) {
                    setState(Phonon::ErrorState);
                    return;
            }

            //we need to play the next media
            play();

            //we tell the video widgets to switch now to the new source
#ifndef QT_NO_PHONON_VIDEO
            for (int i = 0; i < m_videoWidgets.count(); ++i) {
                m_videoWidgets.at(i)->setCurrentGraph(currentGraph()->index());
            }
#endif //QT_NO_PHONON_VIDEO

            emit currentSourceChanged(currentGraph()->mediaSource());
            emit metaDataChanged(currentGraph()->metadata());

            if (nextGraph()->hasVideo() != currentGraph()->hasVideo()) {
                emit hasVideoChanged(currentGraph()->hasVideo());
            }

            emit tick(0);
            emit totalTimeChanged(totalTime());

#ifndef QT_NO_PHONON_MEDIACONTROLLER
            setTitles(currentGraph()->titles());
#endif //QT_NO_PHONON_MEDIACONTROLLER
        }
Esempio n. 12
0
SpectRadio::SpectRadio()
{
	audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
	mediaObject = new Phonon::MediaObject(this);
	mediaObject->setTickInterval(1000);
	connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
	connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
		this, SLOT(stateChanged(Phonon::State,Phonon::State)));
	connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
		this, SLOT(sourceChanged(Phonon::MediaSource)));
	connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));

	Phonon::createPath(mediaObject, audioOutput);
	playlistCurrentRow = -1;

	setupActions();
	setupUi();
	timeLcd->display("00:00");
	setAcceptDrops(true);
}
Esempio n. 13
0
Mpris2::Mpris2(TrayIcon* trayicon) : QObject(trayicon)
{
    m_trayicon = trayicon;

    if (!QDBusConnection::sessionBus().registerService("org.mpris.MediaPlayer2.kdoubanfm")) {
        kWarning() << "registerService failed";
        return;
    }

    new MprisAdaptor(this);
    new MprisPlayerAdaptor(this);

    QDBusConnection::sessionBus().registerObject("/org/mpris/MediaPlayer2", this);

    connect(m_trayicon->m_media, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(slotCurrentSourceChanged()));
    connect(m_trayicon->m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(slotStateChanged(Phonon::State,Phonon::State)));
    connect(m_trayicon->m_output, SIGNAL(volumeChanged(qreal)),
            this, SLOT(slotVolumeChanged(qreal)));
}
Esempio n. 14
0
//![0]
MainWindow::MainWindow()
{
    audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    mediaObject = new Phonon::MediaObject(this);
    metaInformationResolver = new Phonon::MediaObject(this);

    mediaObject->setTickInterval(1000);
//![0]
//![2]
    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
    connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(stateChanged(Phonon::State,Phonon::State)));
    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(sourceChanged(Phonon::MediaSource)));
    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
//![2]

//![1]
    Phonon::createPath(mediaObject, audioOutput);
//![1]

    setupActions();
    setupMenus();
    setupUi();
    timeLcd->display("00:00");
    QList<Phonon::AudioOutputDevice> audioOutputDevices =
            Phonon::BackendCapabilities::availableAudioOutputDevices();

    QList<Phonon::AudioOutputDevice>::iterator i;
    for (i=audioOutputDevices.begin(); i != audioOutputDevices.end(); i++) {
        QString description = (*i).name();
        std::cout << "adi: " << description.toStdString() << "\n";
    }
    audioOutput->setName("Halleluja");


}
Esempio n. 15
0
mainwindow::mainwindow(){
    currentState=0;
    hd = new helpdialog;
    m=new mediaobject;
    setupUi(this);
    setWindowTitle("Music Player");
    m=new mediaobject;
    QObject::connect(actionAbout, SIGNAL(triggered()), this, SLOT(helpShow()));
    QObject::connect(actionExit,SIGNAL(triggered()),this,SLOT(close()));
    QObject::connect(actionAdd_Files,SIGNAL(triggered()),this,SLOT(addFiles()));
    QObject::connect(buttonPause,SIGNAL(clicked()),this,SLOT(pauseFile()));
    QObject::connect(buttonPlay,SIGNAL(clicked()),this,SLOT(playCurrent()));
    QObject::connect(buttonStop,SIGNAL(clicked()),m->mobj,SLOT(stop()));
    QObject::connect(m,SIGNAL(currentSourceChanged(Phonon::MediaSource)),this,SLOT(fetchNext(Phonon::MediaSource)));
    QObject::connect(m->mobj,SIGNAL(aboutToFinish()),this,SLOT(aboutToFinish()));
    QObject::connect(m->mobj,SIGNAL(stateChanged(Phonon::State,Phonon::State)),this,SLOT(metaStateChanged(Phonon::State,Phonon::State)));
    seekSlider->setMediaObject(m->mobj);
    volumeSlider->setAudioOutput(m->audioOutput);
    show();
    // Signal and slots for help -> AboutUs

    //m->setQueue(list);
}
Esempio n. 16
0
void SeekSlider::setMediaObject(MediaObject *media)
{
    K_D(SeekSlider);
    if (d->media) {
        disconnect(d->media, 0, this, 0);
    }
    d->media = media;

    if (media) {
        connect(media, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
                SLOT(_k_stateChanged(Phonon::State)));
        connect(media, SIGNAL(totalTimeChanged(qint64)), SLOT(_k_length(qint64)));
        connect(media, SIGNAL(tick(qint64)), SLOT(_k_tick(qint64)));
        connect(media, SIGNAL(seekableChanged(bool)), SLOT(_k_seekableChanged(bool)));
        connect(media, SIGNAL(currentSourceChanged(Phonon::MediaSource)), SLOT(_k_currentSourceChanged()));
        d->_k_stateChanged(media->state());
        d->_k_seekableChanged(media->isSeekable());
        d->_k_length(media->totalTime());
    } else {
        d->_k_stateChanged(Phonon::StoppedState);
        d->_k_seekableChanged(false);
    }
}
Esempio n. 17
0
MainWindow::MainWindow()
{
    audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    mediaObject = new Phonon::MediaObject(this);
    metaInformationResolver = new Phonon::MediaObject(this);

    mediaObject->setTickInterval(1000);
    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
    connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(stateChanged(Phonon::State,Phonon::State)));
    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(sourceChanged(Phonon::MediaSource)));
    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));

    Phonon::createPath(mediaObject, audioOutput);

    setupActions();
    setupMenus();
    setupUi();
    timeLcd->display("00:00");
}
Esempio n. 18
0
doubanFM::doubanFM(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::doubanFM)
{
    qDebug() << Q_FUNC_INFO;
    ui->setupUi(this);


    currentSongIndex = 0;
    pauseState = false;

    _channelListWidget = new channelList(this);
    _channelListWidget->setchannelId(currentChannelId);
    _channelListWidget->move(-_channelListWidget->getInvisibleWidth(),this->geometry().y());

    _pauseMaskWidget = new pauseMaskWidget(this);
    _pauseMaskWidget->move(250,0);
    _pauseMaskWidget->setVisible(false);


    _loginwidget = new doubanLogin(this);
    _loginwidget->move(this->geometry().x(),-_loginwidget->geometry().height());

    _mediaObject = new Phonon::MediaObject(this);
    _audioOutput = new Phonon::AudioOutput(this);
    Phonon::createPath(_mediaObject,_audioOutput);
    ui->seekSlider->setMediaObject(_mediaObject);


    albumImageManager = new QNetworkAccessManager(this);
    _mydouban = new Douban(this);

    readSettings();
    qDebug() << "read setting" << _mydouban->hasLogin();
    if(_mydouban->hasLogin())
    {
        ui->userLoginButton->setToolTip(tr("click to logout"));
        ui->userLabel->setText(_mydouban->getDoubanUser().name);
    }
    else
    {
        ui->userLoginButton->setToolTip(tr("click to login"));
        ui->userLabel->setText(tr("Logout"));
    }

    nextShortCut = new QxtGlobalShortcut(QKeySequence("Alt+s"),this);
    pauseShortCut = new QxtGlobalShortcut(QKeySequence("Alt+p"),this);
    rateShortCut = new QxtGlobalShortcut(QKeySequence("Alt+r"),this);
    trashShortCut = new QxtGlobalShortcut(QKeySequence("Alt+t"),this);

    connect(nextShortCut,SIGNAL(activated()),this,SLOT(onSkipButtonClicked()));
    connect(pauseShortCut,SIGNAL(activated()),this,SLOT(onPauseButtonClicked()));
    connect(rateShortCut,SIGNAL(activated()),this,SLOT(onRateButtonClicked()));
    connect(trashShortCut,SIGNAL(activated()),this,SLOT(onTrashButtonClicked()));


    //connect the mainwidget signals and the slots
    connect(ui->volumeSlider,SIGNAL(valueChanged(int)),this,SLOT(onVolumneChange(int)));
    connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(onPauseButtonClicked()));
    connect(ui->userLoginButton,SIGNAL(clicked()),this,SLOT(onLoginButtonClicked()));
    connect(_mediaObject,SIGNAL(tick(qint64)),this,SLOT(playTick(qint64)));
    connect(albumImageManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(receiveAlbumImage(QNetworkReply*)));
    connect(this,SIGNAL(albumImageRequest(QString)),this,SLOT(onAlbumImage(QString)));
    connect(ui->rateSongButton,SIGNAL(clicked()),this,SLOT(onRateButtonClicked()));
    connect(ui->nextSongButton,SIGNAL(clicked()),this,SLOT(onSkipButtonClicked()));
    connect(ui->byeSongButton,SIGNAL(clicked()),this,SLOT(onTrashButtonClicked()));
    connect(_mediaObject,SIGNAL(currentSourceChanged(Phonon::MediaSource)),this,SLOT(sourceChanged(Phonon::MediaSource)));
    connect(_mediaObject,SIGNAL(stateChanged(Phonon::State,Phonon::State)),this,SLOT(stateChanged(Phonon::State,Phonon::State)));

//    connect the mainwidget signals and the slots of other widget
    connect(this,SIGNAL(sendlogoutRequest()),_mydouban,SLOT(logoutRequest()));
    connect(this,SIGNAL(sendSongListRequest(qint32,quint32,double)),_mydouban,SLOT(newSongListRequest(qint32,quint32,double)));
    connect(this,SIGNAL(sendSkipSongRequest(qint32,quint32,double)),_mydouban,SLOT(skipSongRequest(qint32,quint32,double)));
    connect(this,SIGNAL(sendRateSongRequest(qint32,quint32,double,bool)),_mydouban,SLOT(rateSongRequest(qint32,quint32,double,bool)));
    connect(this,SIGNAL(sendEndSongRequest(qint32,quint32,double)),_mydouban,SLOT(endSongRequest(qint32,quint32,double)));
    connect(this,SIGNAL(sendByeSongRequest(qint32,quint32,double)),_mydouban,SLOT(byeSongRequest(qint32,quint32,double)));

//  connect the signals of other widget and the mainwidget slot
    connect(_mydouban,SIGNAL(loginSucceed(DoubanUser)),this,SLOT(loginSucceed(DoubanUser)));
    connect(_mydouban,SIGNAL(sendSongList(QList<DoubanFMSong>)),this,SLOT(receiveSongList(QList<DoubanFMSong>)));
    connect(_mydouban,SIGNAL(sendRateSong(bool)),this,SLOT(receiveRateSong(bool)));
    connect(_mydouban,SIGNAL(sendSkipSong(bool)),this,SLOT(receiveSkipSong(bool)));
    connect(_mydouban,SIGNAL(sendByeSong(bool)),this,SLOT(receiveByeSong(bool)));
    connect(_mydouban,SIGNAL(sendEndSong(bool)),this,SLOT(receiveEndSong(bool)));
    connect(_mydouban,SIGNAL(sendChannelList(QList<DoubanChannel>,bool)),this,SLOT(receiveChannelList(QList<DoubanChannel>,bool)));
    connect(_mydouban,SIGNAL(sendLogoutSucceed(bool)),this,SLOT(logoutSucceed(bool)));
    connect(_pauseMaskWidget,SIGNAL(mousePressed()),this,SLOT(pauseMaskWidgetPressed()));
    connect(_channelListWidget,SIGNAL(channelChanged(qint32)),this,SLOT(receiveChannelChange(qint32)));


    //connect the other widget signal and slots
    connect(_mydouban,SIGNAL(captchaImageLoad(QPixmap)),_loginwidget,SLOT(onCaptchaImageLoad(QPixmap)));
    connect(_mydouban,SIGNAL(loginFailed(QString)),_loginwidget,SLOT(onLoginFailed(QString)));
    connect(_mydouban,SIGNAL(sendChannelList(QList<DoubanChannel>,bool)),_channelListWidget,SLOT(onReceiveChannelList(QList<DoubanChannel>,bool)));
    connect(_loginwidget,SIGNAL(loginRequest(QString,QString,QString)),_mydouban,SLOT(loginRequest(QString,QString,QString)));

    _mydouban->channelListRequest();
}
Esempio n. 19
0
// 初始化播放器
void MyWidget::initPlayer()
{
    // 设置主界面标题、图标和大小
    setWindowTitle(tr("MyPlayer音乐播放器"));
    setWindowIcon(QIcon(":/images/icon.png"));
    setMinimumSize(320, 160);
    setMaximumSize(320, 160);

    // 创建媒体图
    mediaObject = new Phonon::MediaObject(this);
    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(mediaObject, audioOutput);

    // 关联媒体对象的tick()信号来更新播放时间的显示
    connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(updateTime(qint64)));

    // 创建顶部标签,用于显示一些信息
    topLabel = new QLabel(tr("<a href = \" http://www.yafeilinux.com \"> www.yafeilinux.com </a>"));
    topLabel->setTextFormat(Qt::RichText);
    topLabel->setOpenExternalLinks(true);
    topLabel->setAlignment(Qt::AlignCenter);

    // 创建控制播放进度的滑块
    Phonon::SeekSlider *seekSlider = new Phonon::SeekSlider(mediaObject, this);

    // 创建包含播放列表图标、显示时间标签和桌面歌词图标的工具栏
    QToolBar *widgetBar = new QToolBar(this);
    // 显示播放时间的标签
    timeLabel = new QLabel(tr("00:00 / 00:00"), this);
    timeLabel->setToolTip(tr("当前时间 / 总时间"));
    timeLabel->setAlignment(Qt::AlignCenter);
    timeLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    // 创建图标,用于控制是否显示播放列表
    QAction *PLAction = new QAction(tr("PL"), this);
    PLAction->setShortcut(QKeySequence("F4"));
    PLAction->setToolTip(tr("播放列表(F4)"));
    connect(PLAction, SIGNAL(triggered()), this, SLOT(setPlaylistShown()));
    // 创建图标,用于控制是否显示桌面歌词
    QAction *LRCAction = new QAction(tr("LRC"), this);
    LRCAction->setShortcut(QKeySequence("F2"));
    LRCAction->setToolTip(tr("桌面歌词(F2)"));
    connect(LRCAction, SIGNAL(triggered()), this, SLOT(setLrcShown()));
    // 添加到工具栏
    widgetBar->addAction(PLAction);
    widgetBar->addSeparator();
    widgetBar->addWidget(timeLabel);
    widgetBar->addSeparator();
    widgetBar->addAction(LRCAction);

    // 创建播放控制动作工具栏
    QToolBar *toolBar = new QToolBar(this);
    // 播放动作
    playAction = new QAction(this);
    playAction->setIcon(QIcon(":/images/play.png"));
    playAction->setText(tr("播放(F5)"));
    playAction->setShortcut(QKeySequence(tr("F5")));
    connect(playAction, SIGNAL(triggered()), this, SLOT(setPaused()));
    // 停止动作
    stopAction = new QAction(this);
    stopAction->setIcon(QIcon(":/images/stop.png"));
    stopAction->setText(tr("停止(F6)"));
    stopAction->setShortcut(QKeySequence(tr("F6")));
    connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop()));
    // 跳转到上一首动作
    skipBackwardAction = new QAction(this);
    skipBackwardAction->setIcon(QIcon(":/images/skipBackward.png"));
    skipBackwardAction->setText(tr("上一首(Ctrl+Left)"));
    skipBackwardAction->setShortcut(QKeySequence(tr("Ctrl+Left")));
    connect(skipBackwardAction, SIGNAL(triggered()), this, SLOT(skipBackward()));
    // 跳转到下一首动作
    skipForwardAction = new QAction(this);
    skipForwardAction->setIcon(QIcon(":/images/skipForward.png"));
    skipForwardAction->setText(tr("下一首(Ctrl+Right)"));
    skipForwardAction->setShortcut(QKeySequence(tr("Ctrl+Right")));
    connect(skipForwardAction, SIGNAL(triggered()), this, SLOT(skipForward()));
    // 打开文件动作
    QAction *openAction = new QAction(this);
    openAction->setIcon(QIcon(":/images/open.png"));
    openAction->setText(tr("播放文件(Ctrl+O)"));
    openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
    connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
    // 音量控制部件
    Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider(audioOutput, this);
    volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
    // 添加到工具栏
    toolBar->addAction(playAction);
    toolBar->addSeparator();
    toolBar->addAction(stopAction);
    toolBar->addSeparator();
    toolBar->addAction(skipBackwardAction);
    toolBar->addSeparator();
    toolBar->addAction(skipForwardAction);
    toolBar->addSeparator();
    toolBar->addWidget(volumeSlider);
    toolBar->addSeparator();
    toolBar->addAction(openAction);

    // 创建主界面布局管理器
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(topLabel);
    mainLayout->addWidget(seekSlider);
    mainLayout->addWidget(widgetBar);
    mainLayout->addWidget(toolBar);
    setLayout(mainLayout);

    // 在3-2中添加的代码
    connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
            this, SLOT(stateChanged(Phonon::State, Phonon::State)));

    // 以下是在3-3中添加的代码

    // 创建播放列表
    playlist = new MyPlaylist(this);
    connect(playlist, SIGNAL(cellClicked(int, int)), this, SLOT(tableClicked(int)));
    connect(playlist, SIGNAL(playlistClean()), this, SLOT(clearSources()));

    // 创建用来解析媒体的信息的元信息解析器
    metaInformationResolver = new Phonon::MediaObject(this);
    // 需要与AudioOutput连接后才能使用metaInformationResolver来获取歌曲的总时间
    Phonon::AudioOutput *metaInformationAudioOutput =
            new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(metaInformationResolver, metaInformationAudioOutput);
    connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
            this, SLOT(metaStateChanged(Phonon::State, Phonon::State)));

    connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
            this, SLOT(sourceChanged(Phonon::MediaSource)));
    connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));

    // 初始化动作图标的状态
    playAction->setEnabled(false);
    stopAction->setEnabled(false);
    skipBackwardAction->setEnabled(false);
    skipForwardAction->setEnabled(false);
    topLabel->setFocus();

}
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();
}
Esempio n. 21
0
void MpvAudioOutput::event_loop() {
    while (true) {
        auto event = mpv_wait_event(handle_, -1);
        //         qDebug() << "mpv event " << mpv_event_name(event->event_id);
        switch (event->event_id) {
        case MPV_EVENT_SHUTDOWN:
            return;
        case MPV_EVENT_QUEUE_OVERFLOW:
            qWarning() << "mpv queue overflow";
            break;
        case MPV_EVENT_START_FILE:
            setState(AudioState::Buffering);
            break;
        case MPV_EVENT_FILE_LOADED:
            setState(AudioState::Playing);
            emit currentSourceChanged();
            setVolume();
            if (seek_offset_ != -1) {
                seek(seek_offset_);
                seek_offset_ = -1;
            }
            break;
        case MPV_EVENT_END_FILE: {
            auto end_ev = reinterpret_cast<mpv_event_end_file *>(event->data);
            if (end_ev->reason == MPV_END_FILE_REASON_ERROR)
                qWarning() << "Ended file: " << mpv_error_string(end_ev->error);
            break;
        }
        case MPV_EVENT_LOG_MESSAGE: {
            auto log = reinterpret_cast<mpv_event_log_message *>(event->data);
            qDebug() << "mpv [" << log->prefix << "] " << log->text;
            break;
        }
        case MPV_EVENT_PROPERTY_CHANGE: {
            auto prop = reinterpret_cast<mpv_event_property *>(event->data);
            if (prop->format != MPV_FORMAT_NONE && prop->data) {
                if (std::string(prop->name) == "playback-time") {
                    std::string pos(*(reinterpret_cast<char **>(prop->data)));
                    emit tick(pos_to_qint64(pos));
                    if (volumeNeverSet_)
                        setVolume();
                } else if (std::string(prop->name) == "idle") {
                    int idle = *reinterpret_cast<int *>(prop->data);
                    if (idle) {
                        setState(AudioState::Stopped);
                        emit finished();
                    } else
                        setState(AudioState::Playing);
                } else if (std::string(prop->name) == "pause") {
                    int pause = *reinterpret_cast<int *>(prop->data);
                    if (pause)
                        setState(AudioState::Paused);
                    else if (state_ == AudioState::Paused)
                        setState(AudioState::Playing);
                } else if (std::string(prop->name) == "duration") {
                    double v = *reinterpret_cast<double *>(prop->data);
                    emit durationChanged(v);
                } else if (std::string(prop->name) == "metadata") {
                    emit metadataChanged(get_property("media-title").toString(),
                                         get_property("audio-format").toString(),
                                         get_property("audio-params/samplerate").toInt());
                }
            }
            break;
        }
        default:
            break;
        }
    }
}
Esempio n. 22
0
void PhononAudioOutput::currentSourceChangedHandler()
{
    emit currentSourceChanged();
}