10e5af0588
working, also added svg icons to the user interface. the settings button currently does nothing (still work in progress). during testing, i discovered QMediaPlayer would have trouble playing some music files that have an ID3 tag so AudFile was created as a way to read the size of the ID3 tag and step over it when QMediaPlayer reads from the file. although it fixed the playback issue, QMediaPlayer is now having trouble calculating the duration properly without the tag. i already have a solution to the porblem in mind, more to come in the next commit.
58 lines
1.0 KiB
C++
58 lines
1.0 KiB
C++
#include "aud_file.h"
|
|
|
|
AudFile::AudFile(QObject *parent) : QFile(parent)
|
|
{
|
|
offset = 0;
|
|
}
|
|
|
|
AudFile::~AudFile()
|
|
{
|
|
close();
|
|
}
|
|
|
|
bool AudFile::openFile(const QString &path)
|
|
{
|
|
setFileName(path);
|
|
|
|
bool ret = open(QFile::ReadOnly);
|
|
|
|
if (ret)
|
|
{
|
|
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 pos)
|
|
{
|
|
return QFile::seek(pos + offset);
|
|
}
|