refactoring
This commit is contained in:
parent
beba95ccef
commit
727f0cb54e
2 changed files with 27 additions and 15 deletions
|
|
@ -24,20 +24,9 @@ void MusicModel::init(NavigationItemModel *item)
|
||||||
emit currentItemChanged();
|
emit currentItemChanged();
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
clearMediaList();
|
||||||
|
|
||||||
while(mMedia->count() > 0){
|
readMedia(mCurrentItem->getPath());
|
||||||
mMedia->removeMedia(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dir = QDir(mCurrentItem->getPath());
|
|
||||||
if(!dir.exists()) return;
|
|
||||||
|
|
||||||
auto fileNames = dir.entryList(QDir::Files);
|
|
||||||
for(auto file:fileNames){
|
|
||||||
if(file.endsWith(".flac") || file.endsWith(".mp3")){
|
|
||||||
mMedia->addMedia(new VlcMedia(dir.filePath(file), true, mVlc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setMediaTitle(mMedia->at(0));
|
setMediaTitle(mMedia->at(0));
|
||||||
}
|
}
|
||||||
|
|
@ -176,12 +165,32 @@ void MusicModel::reset()
|
||||||
emit mediaLengthChanged();
|
emit mediaLengthChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MusicModel::clearMediaList()
|
||||||
|
{
|
||||||
|
while(mMedia->count() > 0){
|
||||||
|
mMedia->removeMedia(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicModel::readMedia(const QString& path)
|
||||||
|
{
|
||||||
|
auto dir = QDir(path);
|
||||||
|
if(!dir.exists()) return;
|
||||||
|
|
||||||
|
auto fileNames = dir.entryList(QDir::Files);
|
||||||
|
for(auto file:fileNames){
|
||||||
|
if(file.endsWith(".flac") || file.endsWith(".mp3")){
|
||||||
|
mMedia->addMedia(new VlcMedia(dir.filePath(file), true, mVlc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString MusicModel::timeToString(int time)
|
QString MusicModel::timeToString(int time)
|
||||||
{
|
{
|
||||||
int sec = time/1000;
|
int sec = time/1000;
|
||||||
int min = sec/60;
|
int min = sec/60;
|
||||||
sec = sec-min*60;
|
sec = sec-min*60;
|
||||||
QString secStr = sec < 10 ? "0"+QString::number(sec) : QString::number(sec);
|
QString secStr = (sec < 10) ? "0"+QString::number(sec) : QString::number(sec);
|
||||||
return QString::number(min) + ":" + secStr;
|
return QString::number(min) + ":" + secStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,11 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reset();
|
void reset();
|
||||||
QString timeToString(int time);
|
void clearMediaList();
|
||||||
|
void readMedia(const QString& path);
|
||||||
void setMediaTitle(VlcMedia* media);
|
void setMediaTitle(VlcMedia* media);
|
||||||
|
QString timeToString(int time);
|
||||||
|
|
||||||
|
|
||||||
bool mIsPlaying = false;
|
bool mIsPlaying = false;
|
||||||
bool mHasNext = false;
|
bool mHasNext = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue