void PlaybackWidget::update() { //Check if the song is finished, and request the next one from playlist if(state == PLAYING && !BASS_ChannelIsActive(curchan)) { state = STOPPED; emit songOver(); } //Now update the gui elements QWORD pos = BASS_ChannelGetPosition(curchan, BASS_POS_BYTE); int ms = BASS_ChannelBytes2Seconds(curchan, pos); float ratio = (float)ms/cursonglength; ui.playedLbl->setText(msToString(ms)); ui.totalLbl->setText("-" + msToString(cursonglength - ms)); int val = ratio*ui.playSlider->maximum(); ui.playSlider->setValue(val); }
void tcClientCtrl::poll() { tsUserData data; if(mpDB->getDBUser(data)) { // Append the server address to the song path if(!data.gsSongData.gsPath.isEmpty()) { data.gsSongData.gsPath = (QString("http://%1%2").arg(msMediaServer).arg(data.gsSongData.gsPath)).replace(" ", "%20"); } // if the stream is null start a new one if(mpStream == NULL) { qDebug() << "Creating new Stream"; mpStream = new tcStreamThread(this); connect(mpStream, SIGNAL(songInfo(qint64,qint64)), this, SLOT(onSongInfo(qint64,qint64))); connect(mpStream, SIGNAL(songOver()), this, SLOT(onSongOver())); mpStream->checkUser(&data); } else if(data.gnUserId != msUser.gnUserId) { qDebug() << "Restarting stream"; // This is a different user to restart the stream if(mpStream->isRunning()) { mpStream->quit(); while(mpStream->isRunning()); } disconnect(mpStream, SIGNAL(songInfo(qint64,qint64)), this, SLOT(onSongInfo(qint64,qint64))); disconnect(mpStream, SIGNAL(songOver()), this, SLOT(onSongOver())); mpStream->deleteLater(); mpStream = new tcStreamThread(this); connect(mpStream, SIGNAL(songInfo(qint64,qint64)), this, SLOT(onSongInfo(qint64,qint64))); connect(mpStream, SIGNAL(songOver()), this, SLOT(onSongOver())); mpStream->checkUser(&data); } else { mpStream->checkUser(&data); } } else if(mpStream != NULL) { qDebug() << "Deleting stream"; // The user is no longer here so kill the stream if(mpStream->isRunning()) { mpStream->quit(); } disconnect(mpStream, SIGNAL(songInfo(qint64,qint64)), this, SLOT(onSongInfo(qint64,qint64))); mpStream->deleteLater(); mpStream = NULL; } msUser = data; // Set the state of our icon mpTray->setState(msUser.gsControlData.gePlayState); // Handle starting/stopping the adintool // and send our heart beat to the DB handleAdinTool(); // Handle any badges in the room handleBadges(); }