コード例 #1
0
void TuneListenerFile::check()
{
    TuneData existedTune = FCurrentTune;
    FCurrentTune.clear(); // just a reset
    if (QFile::exists(FFileName))
    {
        QFile file(FFileName);
        if (file.open(QIODevice::ReadOnly))
            switch (FFileFormat)
            {
                case Plain:
                {
                    QTextStream stream( &file );
                    stream.setCodec("UTF-8");
                    stream.setAutoDetectUnicode(true);
                    FCurrentTune.title = stream.readLine();
                    FCurrentTune.artist = stream.readLine();
                    FCurrentTune.source = stream.readLine();
                    FCurrentTune.track = stream.readLine();
                    FCurrentTune.length = stream.readLine().toInt();
                    break;
                }

                case XML:
                {
                    QDomDocument d;
                    d.setContent(&file, false);
                    QDomElement now_playing=d.documentElement();
                    QDomElement song=now_playing.firstChildElement("song");
                    if (!song.firstChildElement("title").text().isNull())
                        FCurrentTune.title = song.firstChildElement("title").text();
                    if (!song.firstChildElement("artist").text().isNull())
                        FCurrentTune.artist = song.firstChildElement("artist").text();
                    if (!song.firstChildElement("album").text().isNull())
                        FCurrentTune.source = song.firstChildElement("album").text();
                    if (!song.firstChildElement("track").text().isNull())
                        FCurrentTune.track = song.firstChildElement("track").text();
                    if (!song.firstChildElement("length").text().isNull())
                        FCurrentTune.length = song.firstChildElement("length").text().toInt();
                }
            }
    }
    else if (!FWaitForCreated && existedTune.isEmpty())
    {
        FWaitForCreated = true;
        return; // we will return to this function when file created. just exit for now.
    }
    // Common code
    TuneData tune = currentTune();
    if (FPreviousTune != tune)
    {
        FPreviousTune = tune;
        if (tune.isEmpty())
            emit stopped();
        else
            emit playing(tune);
    }
}
コード例 #2
0
/**
 * Polls for new song info.
 */
void PollingTuneController::check()
{
	Tune tune = currentTune();
	if (prev_tune_ != tune) {
		prev_tune_ = tune;
		if (tune.isNull()) {
			emit stopped();
		}
		else {
			emit playing(tune);
		}
	}
}
コード例 #3
0
void QompQtMultimediaPlayer::doSetTune()
{
#ifdef DEBUG_OUTPUT
	qDebug() << "QompQtMultimediaPlayer::doSetTune()";
#endif
	if(!player_->media().isNull()) {
		player_->blockSignals(true);
		player_->setMedia(QMediaContent());
		player_->blockSignals(false);
	}

	if(watcher_) {
		watcher_->parent()->setProperty("blocked", true);
	}

	GetTuneUrlHelper* helper = new GetTuneUrlHelper(this, "tuneUrlReady", this);
	watcher_ = helper->getTuneUrlAsynchronously(currentTune());
}