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(); }
/** * Nofication.beep - http://docs.phonegap.com/phonegap_notification_notification.md.html#notification.beep */ void Notification::beep( int scId, int ecId, int p_times ) { Q_UNUSED(scId) Q_UNUSED(ecId) Q_UNUSED(p_times) QMediaPlayer* player = new QMediaPlayer; player->setVolume(100); player->setMedia(QUrl::fromLocalFile("/usr/share/sounds/ui-tones/snd_default_beep.wav")); player->play(); }
void MainWindow::on_pushButton_clicked() { player.stop(); float number; std::istringstream iss(std_str); iss >> number ; int num = number *1000; player.setMedia(QUrl::fromLocalFile(QFileInfo(file_main).absoluteFilePath())); player.setVolume(100); player.play(); delay(num+2); qDebug() << num << endl; player2.setMedia(QUrl::fromLocalFile(QFileInfo(file_ref).absoluteFilePath())); player2.setVolume(100); player2.play(); }
MovieDisplay::MovieDisplay(QWidget *parent) : QDialog(parent), ui(new Ui::MovieDisplay) { ui->setupUi(this); //This block of code displays Llama gif when a riddle is anwsered correctly QMovie *movie = new QMovie("://images/pm8gm.gif"); QLabel *processLabel = new QLabel(this); processLabel->setGeometry(QRect(0,-75,300,300)); processLabel->setMovie(movie); movie->start(); //This block of code plays an audio file when a riddle is answered correctly. //IMPORTANT::Audio path must be hard coded to location of file! QMediaPlayer *player = new QMediaPlayer(this); player->setVolume(50); player->setMedia(QUrl("http://shredder.resnet.bju/sound/649341_SOUNDDOGS__an.mp3")); player->setVolume(100); player->play(); }
void Form::getVoice() { QMediaPlayer* player = new QMediaPlayer(); QUrl url(m_word.voice_url); player->setMedia(url); player->setVolume(100); player->play(); m_reply = m_net_manager.get(QNetworkRequest(url)); connect(m_reply,SIGNAL(finished()),this,SLOT(downloadFinished())); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); //QSystemTrayIcon tray; //tray.show(); QMediaPlayer player; player.setVolume(100); QMediaPlaylist myList; player.setPlaylist(&myList); PlayerWindow w(0, &player); w.show(); return a.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap startPixmap(":/new/icon/icon/flower.gif"); startPixmap.size(); QSplashScreen splash(startPixmap); splash.show(); for(long i=0; i<100000000;i++); MainWindow w; w.show(); splash.finish(&w); QMediaPlayer *player = new QMediaPlayer; player->setMedia(QUrl::fromUserInput("qrc:/new/sound/1.wav")); player->setVolume(50); player->play(); return a.exec(); }
void MainWindow::showEvent(QShowEvent *) { // play music QMediaPlayer *player = new QMediaPlayer(); player->setMedia(QUrl("qrc:/sound/Fight.mp3")); player->setVolume(60); player->play(); // Setting the QGraphicsScene scene = new QGraphicsScene(0,0,960,540); ui->graphicsView->setScene(scene); ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff ); // Create world world = new b2World(b2Vec2(0.0f, -9.8f)); // Create self listener and set to the world myContactListener = new myContactChecker(); world->SetContactListener(myContactListener); // Setting Size GameItem::setGlobalSize(QSizeF(64,36), QSizeF(960,540)); // Create manager mySceneManager = new sceneManager(&timer,world,scene); myBirdManager = new birdManager(&timer,world,scene); // Game process // set up start page mySceneManager->buildStartScene(); this->buildStartButton(); // wait user to click play button // go see 'onStartButton'(1st) //mySceneManager->buildLossScene(); //this->buildEndButton(); // Timer connect(&timer,SIGNAL(timeout()),this,SLOT(tick())); connect(this,SIGNAL(quitGame()),this,SLOT(QUITSLOT())); timer.start(100/6); }
HomePage::HomePage(QWidget *parent) : QWidget(parent), ui(new Ui::HomePage) { ui->setupUi(this); //Initialize the splash screen and allow user to exit if they click on it QMovie *splashImg = new QMovie(":/icons/resources_icons/ProjectLogo_LoopOnce.gif"); ui->label->setMovie(splashImg); ui->label->setFixedSize(900,450); QMediaPlayer *player = new QMediaPlayer; player->setMedia(QUrl("qrc:/audio/resources_icons/ProjectLogoSound.mp3")); player->setVolume(100); player->setPlaybackRate(0.85); player->play(); //Connect the signal on every frame change to check for last frame since it loops infinitely connect(splashImg, SIGNAL(finished()), this, SLOT(EmitFinished())); splashImg->start(); }
/*! * \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 } if(PlayerLife==0) { #ifdef __WIN32__ player.stop(); player.setMedia(playlist[2]); // on joue la musique de game over player.play(); #endif MainFont(KNoir,KRouge, KNoir); // image de game over } FinalScore += Score; if(Level == 4) { #ifdef __WIN32__ player.stop(); player.setMedia(playlist[1]); // musique de victoire player.play(); #endif MainFont(KNoir,KVert, KNoir); // image de victoire cout << "Score Final "<< FinalScore; // affichage du score final } } }