qt for android 之实现后台扫描音乐文件
手机多媒体开发的时候经常需要后台扫描音乐文件,本篇使用qt一些库实现简单的后台扫描的类,继承了Qthread
playlist.h
ifndef PLAYLIST_H
define PLAYLIST_H
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
class PlayList : public QThread
{
Q_OBJECT
public:
explicit PlayList(QObject *parent = 0);
~PlayList();
Q_PROPERTY(QJsonArray playlist READ playlist NOTIFY playlistChanged)QJsonArray playlist();Q_INVOKABLE void findMusic();Q_INVOKABLE int getItemsLength(){ return musicPath.count();}Q_INVOKABLE QString getMusicName(int id){ return musicPath.at(id).fileName();}Q_INVOKABLE QString getMusicPath(int id){ return musicPath.at(id).filePath();}void run();
signals:
void playlistChanged();
public slots:
private:
QList musicPath;
};
endif // PLAYLIST_H
playlist.cpp
include "playlist.h"
PlayList::PlayList(QObject *parent) : QThread(parent)
{
}
PlayList::~PlayList()
{
}
void PlayList::findMusic(){
this->start();
}
QJsonArray PlayList::playlist(){
QJsonArray jsarr;
QMutex mutex;
mutex.lock();
for(auto it:musicPath){
QJsonObject obj;
obj.insert("name",it.fileName());
obj.insert("path","file://"+it.filePath());
jsarr.append(obj);
}
mutex.unlock();
return jsarr;
}
void PlayList::run(){
QMutex mutex;
mutex.lock();
QString path="/mnt/sdcard";
//get all files's filtersQStringList filters;filters
效果图:
关键字:qt5, #c++#
版权声明
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!