本文整理汇总了C++中QMediaPlayer::state方法的典型用法代码示例。如果您正苦于以下问题:C++ QMediaPlayer::state方法的具体用法?C++ QMediaPlayer::state怎么用?C++ QMediaPlayer::state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMediaPlayer
的用法示例。
在下文中一共展示了QMediaPlayer::state方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: play
void Audio::play(const QString &filename, const bool doubleVolume)
{
if (SoundCache == nullptr)
return;
QMediaPlayer *sound = nullptr;
if (!SoundCache->contains(filename))
{
sound = new QMediaPlayer;
sound->setMedia(QUrl(filename));
SoundCache->insert(filename, sound);
}
else
{
sound = SoundCache->object(filename);
if (sound->state() == QMediaPlayer::PlayingState)
{
return;
}
}
if (sound == nullptr)
return;
sound->setVolume((doubleVolume ? 2 : 1) * Config.EffectVolume * 100);
sound->play();
}
示例2: QGraphicsPixmapItem
Bullet::Bullet()
:QObject(),
QGraphicsPixmapItem()
{
setPixmap(QPixmap(":/images/rocket.png"));
QTimer *timer = new QTimer();
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(move()));
timer->start(50);
//sound bullet
QMediaPlayer *bulletSound = new QMediaPlayer();
bulletSound->setMedia(QUrl("qrc:/sounds/shoot.wav"));
//sound
if (bulletSound->state() == QMediaPlayer::PlayingState)
{
bulletSound->setPosition(0); //rewind
}
else bulletSound->play(); //it should be in QMediaPlayer::StoppedState
}
示例3: while
void TSR::syncedPlay2(QString file)
{
TIMER_STATE ts2 = ts;
QMediaPlayer player;
player.setMedia(QUrl::fromLocalFile(file));
player.play();
totalTime = player.duration() / 1000;
time.start();
while(player.state() == QMediaPlayer::PlayingState)
{
totalTime = player.duration() / 1000;
elapsedTime = player.position() / 1000;
QCoreApplication::processEvents();
if(ts == TS_STOPPED) break;
if(ts != ts2) break;
QThread::msleep(20);
}
elapsedTime = 0; totalTime = 0;
}
示例4: Run
/*!
* \brief Run
* Programe principale du jeux
*/
void Run()
{
#ifdef __WIN32__
QThread Thread; // on crée un objet QThread pour le Timer de QMediaPlayer
QMediaPlayer player; // on crée un lecteur de Musique
player.moveToThread(&Thread); // on le place dans le Thread
player.setVolume(50); // on modifie le volume
QVector<QUrl> playlist; // on affecte une playlist d'URL
playlist.push_back(QUrl(QString::fromStdString(KIntroSound)));
playlist.push_back(QUrl(QString::fromStdString(KEndSound)));
playlist.push_back(QUrl(QString::fromStdString(KGameOverSound)));
playlist.push_back(QUrl(QString::fromStdString(KHistoSound)));
playlist.push_back(QUrl(QString::fromStdString(KGameSound)));
player.setMedia(playlist[0]);
player.play(); // On joue la musque d'introduction au jeux
#endif
srand (time(NULL));
set_input_mode();
MainFont(); // On affiche un Invader
CVString Space; // On crée la variable qui est la grille de jeux
int FinalScore(0); // variable qui stock le score
unsigned Level(0); // variable qui stock le niveau atteint par le joueur
for( ; Level<5 && (Level==0 || !LoseTest(Space, Space.size()-1)) ; ++Level)
{
unsigned PosInvader(KBegInvader), PosMe(KBegMe); // Variable stockant la position de l'invader et du joueur
unsigned LineInvader(0); // ligne de l'invader
unsigned FirstInvaderCount (KInvadersSize); // Compteur du nombre d'invaders restant
if(Level>2)
FirstInvaderCount = KInvadersSize*2/3;
unsigned PlayerLife (KMyLife); // Variable stockant la vie du joueur
int Score(0); // score du joueur
bool Increment(true); // variable qui donne le sens de déplacement de l'invader
int FireWait(0); // Variable evitant que le joueur puisse tiré rapidement
initSpace(Space, PosMe, LineInvader); // Variable initialisant
cout << CleanScreen(); // on efface l'écran pour rafraichir l'image
#ifdef __WIN32__
player.stop();
player.setMedia(playlist[3]); // on joue la musique de scenario
player.play();
#endif
ManageScenar(Level); // démarage de l'affichage du scénario
#ifdef __WIN32__
player.stop();
player.setMedia(playlist[4]); // a la fin du scenario on lance la musique de jeux
player.play();
#endif
cout << CleanScreen(); // on efface l'écran
unsigned Turn(0); // nombre de tours écoulés
while(!WinTest(Space, LineInvader) && !LoseTest(Space, Space.size()-1)) // on boucle tan que le joueur ou l'invader n'a pas gagne ou qu'il soit arrive sur la dernier ligne
{
Score -= 10; // on decremente le score à chaque tours de l'invader
for(unsigned i(0) ; i<KRatioMeInvaders && (!WinTest(Space, LineInvader) && !LoseTest(Space, Space.size()-1)); ++i, ++Turn) // boucle pour equilibré le ration
{
unsigned LastInvaderCount (FirstInvaderCount); // on sauvegarde le nombre d'invaders avant de faire se déplacer les missile
ManageMissileAndTorpedo(Space, FirstInvaderCount, PlayerLife, Score);
if(LastInvaderCount != FirstInvaderCount) // si il manque un ou plusieurs invaders on incrémente le score et on fait apparaitre un bonus
{
ManageBonus(Space, LineInvader);
Score += 100;
}
if(Turn%KMissileRatio == 0) // on respecte un ratio pour les tirs de missile
ManageInvaderShoot(Space, LineInvader, PosInvader, PlayerLife);
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now(); // on recupère le temps de début
ManageMe(Space, PosMe, FireWait, PlayerLife, Score); // on donne le tour au joueur
cout << GotoXY(0,0) << "\t\t\t" << SetColorAndBack(KNoir, KRouge) << string(KSizeLine+2,'-') << Reset() << endl; // place le haut de la grille
for(const string &Line : Space)
{
cout << "\t\t\t" << SetColorAndBack(KNoir, KRouge) << '|' << Reset(); // on affiche la grille de jeux
PrintGameLine(Line);
cout << SetColorAndBack(KNoir, KRouge) << '|' << Reset() << endl;
}
cout << "\t\t\t" << SetColorAndBack(KNoir, KRouge) << string(KSizeLine+2,'-') << Reset() << endl;
cout << SetColorAndBack(KCyan, KRouge) << resizeText(" Score : " + to_string(Score) + " Player Life : " + to_string(PlayerLife), 60) << Reset() << endl; // afficher les info du jeux
cout << SetColorAndBack(KCyan, KRouge) << resizeText(" FinalScore : " + to_string(Score + FinalScore) + " Invader Count : " + to_string(FirstInvaderCount),60)<< Reset() << endl;
chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>( t2 - t1 ).count(); // on fait la différence pour eviter que le jeux aille trop vite
if(duration<350000)
usleep(350000-duration); // on attend que le temps manquant ce soit écoulé
}
#ifdef __WIN32__
if(player.state() != QMediaPlayer::PlayingState) // si la musique s'arrete on la relance
player.play();
#endif
ManageInvaderMove(Space, Increment, LineInvader, PosInvader); // on déplace l'invader
//.........这里部分代码省略.........
示例5: paintEvent
void WaveformView::paintEvent(QPaintEvent *event)
{
PG_UNUSED(event);
QPainter dc(this);
int32 clientWidth = width();
int32 clientHeight = height();
if (fDoc == NULL)
{
dc.drawText(QRect(0, 0, clientWidth, clientHeight), Qt::AlignHCenter | Qt::AlignVCenter, tr("Drop WAV audio file here"));
return;
}
int32 topBorder = 16; // should be the height of frame label text
int32 halfClientHeight;
int32 sampleHeight, halfSampleHeight, textHeight;
int32 fps = fDoc->Fps();
int32 x = 0;
int32 frameX;
int32 sample = 0;
int32 frame = 0;
bool drawPlayMarker = false;
QRect r;
QColor textCol(64, 64, 64);
QColor sampleFillCol(162, 205, 242);
QColor sampleOutlineCol(30, 121, 198);
QColor playBackCol(255, 127, 127);
QColor playForeCol(209, 102, 121, 128);
QColor playOutlineCol(128, 0, 0);
QColor frameCol(192, 192, 192);
QColor phraseFillCol(205, 242, 162);
QColor phraseOutlineCol(121, 198, 30);
QColor wordFillCol(242, 205, 162);
QColor wordOutlineCol(198, 121, 30);
QColor wordMissingFillCol(255, 127, 127);
QColor wordMissingOutlineCol(255, 0, 0);
QColor phonemeFillCol(231, 185, 210);
QColor phonemeOutlineCol(173, 114, 146);
QMediaPlayer *audioPlayer = fDoc->GetAudioPlayer();
textHeight = dc.fontMetrics().height() + 4;
topBorder = textHeight;
halfClientHeight = (clientHeight - textHeight) / 2;
if (audioPlayer && audioPlayer->state() == QMediaPlayer::PlayingState)
{
drawPlayMarker = true;
x = fCurFrame * fFrameWidth;
dc.fillRect(QRect(x, 0, fFrameWidth, clientHeight), playBackCol);
}
x = 0;
for (int32 i = 0; i < fNumSamples; i++)
{
if (((sample + 1) % fSamplesPerFrame) == 0)
{
dc.setPen(frameCol);
// draw frame marker
frameX = (frame + 1) * fFrameWidth;
if (fSampleWidth >= 2 && ((fFrameWidth > 2) || ((frame + 2) % fps == 0)))
{
dc.drawLine(frameX, topBorder, frameX, clientHeight);
}
// draw frame label
if ((fFrameWidth > 30) || ((frame + 2) % fps == 0))
{
dc.drawLine(frameX, 0, frameX, topBorder);
dc.drawText(frameX + 2, textHeight - 4, QString::number(frame + 2));
}
}
sampleHeight = PG_ROUND(fAmp[i] * (real)(clientHeight - topBorder));
halfSampleHeight = sampleHeight / 2;
r.setRect(x, topBorder + halfClientHeight - halfSampleHeight, fSampleWidth + 1, sampleHeight);
dc.fillRect(r, sampleFillCol);
dc.setPen(sampleOutlineCol);
dc.drawLine(r.topLeft(), r.topRight());
dc.drawLine(r.bottomLeft(), r.bottomRight());
dc.drawLine(r.topRight(), r.bottomRight());
if (i == 0)
{
dc.drawLine(r.topLeft(), r.bottomLeft());
}
else if (fAmp[i] > fAmp[i - 1])
{
sampleHeight = PG_ROUND(fAmp[i - 1] * (real)(clientHeight - topBorder));
halfSampleHeight = sampleHeight / 2;
dc.drawLine(r.topLeft(), QPoint(r.left(), topBorder + halfClientHeight - halfSampleHeight));
dc.drawLine(r.bottomLeft(), QPoint(r.left(), topBorder + halfClientHeight - halfSampleHeight + sampleHeight - 1));
}
x += fSampleWidth;
sample++;
if ((sample % fSamplesPerFrame) == 0)
frame++;
}
if (fDoc->fCurrentVoice)
//.........这里部分代码省略.........
示例6: positionChanged
void WaveformView::positionChanged(qint64 milliseconds)
{
if (fDoc)
{
real f = ((real)milliseconds / 1000.0f) * fDoc->Fps();
int32 frame = PG_FLOOR(f);
if (frame != fCurFrame)
{
if (fAudioStopFrame >= 0)
{
if (frame > fAudioStopFrame)
{
if (fDoc->GetAudioPlayer())
fDoc->GetAudioPlayer()->stop();
fAudioStopFrame = -1;
}
else
{
fCurFrame = frame;
emit(frameChanged(fCurFrame));
}
update();
}
else if (fDragging)
{
if (frame > fCurFrame + 1)
{
if (fDoc->GetAudioPlayer())
fDoc->GetAudioPlayer()->stop();
}
}
else
{
fCurFrame = frame;
emit(frameChanged(fCurFrame));
update();
}
QMediaPlayer *audioPlayer = fDoc->GetAudioPlayer();
if (!fDragging && audioPlayer && audioPlayer->state() == QMediaPlayer::PlayingState)
{
if (fScrollArea)
{
QScrollBar *scrollBar = fScrollArea->horizontalScrollBar();
if (scrollBar)
{
int frameX = fCurFrame * fFrameWidth;
int scrollX = scrollBar->value();
int scrollW = fScrollArea->width();
if (frameX - scrollX > scrollW)
{
scrollBar->setValue(frameX - scrollW / 6);
}
else if (frameX - scrollX < 0)
scrollBar->setValue(frameX);
}
}
}
}
}
}