73a8c03fa1
and added some options to the menu that changes the behaviour of the app. such as turning on/off the auto playing of files and the directory and volume control. this is all kept persistent using an IDM formated file in the app's config directory. still having issues with it not calculating the durations properly but i now know why. it's because QMediaPlayer can't calculate the durations of VBR files (variable bit- rate) properly. other than that, everything seems to be working perfectly. i'll add more feasures such as a next/previous file button and a stop button.
67 lines
1.1 KiB
C++
67 lines
1.1 KiB
C++
#include "aud_file.h"
|
|
|
|
AudFile::AudFile(QObject *parent) : QFile(parent)
|
|
{
|
|
offset = 0;
|
|
}
|
|
|
|
AudFile::~AudFile()
|
|
{
|
|
close();
|
|
}
|
|
|
|
bool AudFile::openFile(const QString &path)
|
|
{
|
|
close();
|
|
|
|
setFileName(path);
|
|
|
|
bool ret = open(QFile::ReadOnly);
|
|
|
|
if (ret)
|
|
{
|
|
offset = 0;
|
|
|
|
if (peek(3) == "ID3")
|
|
{
|
|
QByteArray header = read(10);
|
|
QByteArray intBytes = header.mid(6);
|
|
quint64 num = 0;
|
|
quint64 bit = 1;
|
|
|
|
offset += 10;
|
|
|
|
if (header[5] & 16) //Footer flag check
|
|
{
|
|
offset += 10;
|
|
}
|
|
|
|
for (int i = intBytes.size() - 1; i >= 0; --i)
|
|
{
|
|
int byte = intBytes[i];
|
|
|
|
for (int inBit = 1; inBit <= 64; inBit *= 2, bit *= 2)
|
|
{
|
|
if ((byte & inBit) != 0) num |= bit;
|
|
}
|
|
}
|
|
|
|
offset += num;
|
|
}
|
|
|
|
seek(0);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
bool AudFile::seek(qint64 off)
|
|
{
|
|
return QFile::seek(offset + off);
|
|
}
|
|
|
|
qint64 AudFile::size() const
|
|
{
|
|
return QFile::size() - offset;
|
|
}
|