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 :
#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(){
soundEffect
->setMedia
(QUrl("qrc:/Story_Sounds/PlaneEngine.wav"));
if(soundEffect->state() == QMediaPlayer::PlayingState){
soundEffect->stop();
}else if(soundEffect->state() == QMediaPlayer::StoppedState){
soundEffect->play();
}
}
#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(){
soundEffect->setMedia(QUrl("qrc:/Story_Sounds/PlaneEngine.wav"));
if(soundEffect->state() == QMediaPlayer::PlayingState){
soundEffect->stop();
}else if(soundEffect->state() == QMediaPlayer::StoppedState){
soundEffect->play();
}
}
To copy to clipboard, switch view to plain text mode
I call the function in game.cpp 3 times like this:
soundEffects->playPlaneEngineSound();
soundEffects->playPlaneEngineSound();
SoundEffects->playPlaneEngineSound();
soundEffects->playPlaneEngineSound();
soundEffects->playPlaneEngineSound();
SoundEffects->playPlaneEngineSound();
To copy to clipboard, switch view to plain text mode
and the application crashes and i don't know why...
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 ).
Bookmarks