Hello !
so i have this function in a class that plays an audio file and stops it if it's being active.
This is the class and its function :
Code:
#include "soundeffects.h" #include <QMediaPlayer> #include <QMediaPlaylist> // klas sound effectov sm naredu in potem jih sam klicm ko jih rabm na primer ko pritisnem SPACE se zazene // canonBallShot funkcija in sound effect ki se nahaj v tej funkciji; SoundEffects::SoundEffects(){ soundEffect = new QMediaPlayer; } void SoundEffects::playPlaneEngineSound(){ if(soundEffect->state() == QMediaPlayer::PlayingState){ soundEffect->stop(); }else if(soundEffect->state() == QMediaPlayer::StoppedState){ soundEffect->play(); } }
I call the function in game.cpp 3 times like this:
and the application crashes and i don't know why...Code:
soundEffects->playPlaneEngineSound(); soundEffects->playPlaneEngineSound(); SoundEffects->playPlaneEngineSound();
Could it be because i set media again when the function is called the third time ?
And if how do i fix it so that when i call the function once, it plays the sound, second time it stops it and so on ( checking if it's active or not and depending on the output the audio is played or stopped ).