I am using qt5.0. I created a dll and put all my audio files inside the dll. Now I create a file from the resource and the game. It works fine.
But the problem is that after playing the file, I canβt delete this file and recreate the new file.
if I try to delete manually, I also get an error. "some other program using this file". as soon as I stop the program, then I can only delete the file.
How to delete a file after immediate palyback. here is my code
player = new QMediaPlayer; connect(player,SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),this,SLOT(mediaStatusChanged(QMediaPlayer::MediaStatus))); QFile file2(QDir::tempPath() + "/temp0.mp3"); if (file2.open(QIODevice::ReadWrite)) { QFile workFile(":/AUDIO/" + fn +".mp3"); if(workFile.open(QIODevice::ReadOnly)) { file2.write(workFile.readAll()); workFile.close(); } file2.close(); } player->setMedia(QMediaContent(QUrl::fromLocalFile(QDir::tempPath() + "/temp0.mp3"))); player->setVolume(100); player->play();
void Audio::mediaStatusChanged(QMediaPlayer::MediaStatus state) { if(state==QMediaPlayer::EndOfMedia) { QFile::remove(QDir::tempPath() + "/temp0.mp3"); qDebug()<<"Audio played"; } }
I get the message "Audio play", but does not delete the file.
please help me solve this problem.
source share