1 Star 1 Fork 0

yuwei/QtFFmpegVideoPlayer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
playlist.cpp 5.25 KB
一键复制 编辑 原始数据 按行查看 历史
yuwei 提交于 2024-04-26 12:30 . 初始版本
#include <QDebug>
#include <QDir>
#include "playlist.h"
#include "ui_playlist.h"
#include "globalhelper.h"
Playlist::Playlist(QWidget* parent) :
QWidget(parent),
ui(new Ui::Playlist)
{
ui->setupUi(this);
}
Playlist::~Playlist()
{
QStringList strListPlayList;
for (int i = 0; i < ui->List->count(); i++)
{
strListPlayList.append(ui->List->item(i)->toolTip());
}
GlobalHelper::SavePlaylist(strListPlayList);
delete ui;
}
bool Playlist::Init()
{
if (ui->List->Init() == false)
{
return false;
}
if (InitUi() == false)
{
return false;
}
if (ConnectSignalSlots() == false)
{
return false;
}
setAcceptDrops(true);
return true;
}
bool Playlist::InitUi()
{
setStyleSheet(GlobalHelper::GetQssStr("://res/qss/playlist.css"));
//ui->List->hide();
//this->setFixedWidth(ui->HideOrShowBtn->width());
//GlobalHelper::SetIcon(ui->HideOrShowBtn, 12, QChar(0xf104));
ui->List->clear();
QStringList strListPlaylist;
GlobalHelper::GetPlaylist(strListPlaylist);
for (QString strVideoFile : strListPlaylist)
{
QFileInfo fileInfo(strVideoFile);
if (fileInfo.exists())
{
QListWidgetItem* pItem = new QListWidgetItem(ui->List);
pItem->setData(Qt::UserRole, QVariant(fileInfo.filePath())); // 用户数据
pItem->setText(QString("%1").arg(fileInfo.fileName())); // 显示文本
pItem->setToolTip(fileInfo.filePath());
ui->List->addItem(pItem);
}
}
if (strListPlaylist.length() > 0)
{
ui->List->setCurrentRow(0);
}
//ui->List->addItems(strListPlaylist);
return true;
}
bool Playlist::ConnectSignalSlots()
{
QList<bool> listRet;
bool bRet;
bRet = connect(ui->List, &MediaList::SigAddFile, this, &Playlist::OnAddFile);
listRet.append(bRet);
for (bool bReturn : listRet)
{
if (bReturn == false)
{
return false;
}
}
return true;
}
void Playlist::on_List_itemDoubleClicked(QListWidgetItem* item)
{
emit SigPlay(item->data(Qt::UserRole).toString());
m_nCurrentPlayListIndex = ui->List->row(item);
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
bool Playlist::GetPlaylistStatus()
{
if (this->isHidden())
{
return false;
}
return true;
}
int Playlist::GetCurrentIndex()
{
return 0;
}
void Playlist::OnAddFile(QString strFileName)
{
bool bSupportMovie = strFileName.endsWith(".mkv", Qt::CaseInsensitive) ||
strFileName.endsWith(".rmvb", Qt::CaseInsensitive) ||
strFileName.endsWith(".mp4", Qt::CaseInsensitive) ||
strFileName.endsWith(".avi", Qt::CaseInsensitive) ||
strFileName.endsWith(".flv", Qt::CaseInsensitive) ||
strFileName.endsWith(".wmv", Qt::CaseInsensitive) ||
strFileName.endsWith(".3gp", Qt::CaseInsensitive) ||
strFileName.endsWith(".mov", Qt::CaseInsensitive);
if (!bSupportMovie)
{
return;
}
QFileInfo fileInfo(strFileName);
QList<QListWidgetItem*> listItem = ui->List->findItems(fileInfo.fileName(), Qt::MatchExactly);
QListWidgetItem* pItem = nullptr;
if (listItem.isEmpty())
{
pItem = new QListWidgetItem(ui->List);
pItem->setData(Qt::UserRole, QVariant(fileInfo.filePath())); // 用户数据
pItem->setText(fileInfo.fileName()); // 显示文本
pItem->setToolTip(fileInfo.filePath());
ui->List->addItem(pItem);
}
else
{
pItem = listItem.at(0);
}
}
void Playlist::OnAddFileAndPlay(QString strFileName)
{
bool bSupportMovie = strFileName.endsWith(".mkv", Qt::CaseInsensitive) ||
strFileName.endsWith(".rmvb", Qt::CaseInsensitive) ||
strFileName.endsWith(".mp4", Qt::CaseInsensitive) ||
strFileName.endsWith(".avi", Qt::CaseInsensitive) ||
strFileName.endsWith(".flv", Qt::CaseInsensitive) ||
strFileName.endsWith(".wmv", Qt::CaseInsensitive) ||
strFileName.endsWith(".3gp", Qt::CaseInsensitive);
if (!bSupportMovie)
{
return;
}
QFileInfo fileInfo(strFileName);
QList<QListWidgetItem*> listItem = ui->List->findItems(fileInfo.fileName(), Qt::MatchExactly);
QListWidgetItem* pItem = nullptr;
if (listItem.isEmpty())
{
pItem = new QListWidgetItem(ui->List);
pItem->setData(Qt::UserRole, QVariant(fileInfo.filePath())); // 用户数据
pItem->setText(fileInfo.fileName()); // 显示文本
pItem->setToolTip(fileInfo.filePath());
ui->List->addItem(pItem);
}
else
{
pItem = listItem.at(0);
}
on_List_itemDoubleClicked(pItem);
}
void Playlist::OnBackwardPlay()
{
if (m_nCurrentPlayListIndex == 0)
{
m_nCurrentPlayListIndex = ui->List->count() - 1;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
else
{
m_nCurrentPlayListIndex--;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
}
void Playlist::OnForwardPlay()
{
if (m_nCurrentPlayListIndex == ui->List->count() - 1)
{
m_nCurrentPlayListIndex = 0;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
else
{
m_nCurrentPlayListIndex++;
on_List_itemDoubleClicked(ui->List->item(m_nCurrentPlayListIndex));
ui->List->setCurrentRow(m_nCurrentPlayListIndex);
}
}
void Playlist::dropEvent(QDropEvent* event)
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty())
{
return;
}
for (QUrl url : urls)
{
QString strFileName = url.toLocalFile();
OnAddFile(strFileName);
}
}
void Playlist::dragEnterEvent(QDragEnterEvent* event)
{
event->acceptProposedAction();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuwei_2_838529949/qt-ffmpeg-video-player.git
[email protected]:yuwei_2_838529949/qt-ffmpeg-video-player.git
yuwei_2_838529949
qt-ffmpeg-video-player
QtFFmpegVideoPlayer
master

搜索帮助