I'm using qt5.0. I created dll and put all my audio files inside dll. now i am creating file from resource and playing. it's working fine.
But the problem is after playing the file I'm not able to delete that file and recreate new file.
if I try to delete manually also I getting error. "some other program using that file". once i stop the program then only able to delete the file.
How to delete the file after immediate palyback. here 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'm getting "Audio played" message but it's not deleteing the file.
please help me to solve this issue.