/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
***************************************************************************/
#include <QtGui>
#include <QtSql>
#include "mainwindow.h"
#include "Database.h"
MainWindow::MainWindow()
{
readSettings();
count = 0;
model = new QSqlTableModel(this);
model->setTable("playlist");
model->select();
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
metaInformationResolver = new Phonon::MediaObject(this);
videoWidget = new VideoDisplayWidget(mediaObject,metaInformationResolver,&sources,this);
mediaObject->setTickInterval(1000);
connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
connect(mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(stateChanged(Phonon::State,Phonon::State)));
connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
this, SLOT(sourceChanged(Phonon::MediaSource)));
connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
connect(mediaObject,SIGNAL(hasVideoChanged(bool)),this,SLOT(hasVideoInMediaObject(bool)));
connect(this,SIGNAL(changeMediaPlayerUI()),this,SLOT(hasVideoInMediaObject()));
Phonon::createPath(mediaObject, audioOutput);
Phonon::createPath(mediaObject, videoWidget);
setupActions();
setupMenus();
setupUi();
timeLcd->display("00:00");
fetchDataFromDatabase();
}
void MainWindow::addFiles()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Music Files"),
QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
if (files.isEmpty())
return;
int index = sources.size();
foreach (QString string, files) {
Phonon::MediaSource source(string);
sources.append(source);
}
if (!sources.isEmpty())
metaInformationResolver->setCurrentSource(sources.at(index));
}
void MainWindow::about()
{
QMessageBox::information(this, tr("About Phonen Media Player Demo"),
tr("The Phonen Media Player Demo shows how to use Phonon - the multimedia"
" framework that comes with Qt - to create a simple media player."));
}
void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
{
switch (newState) {
case Phonon::ErrorState:
if (mediaObject->errorType() == Phonon::FatalError) {
QMessageBox::warning(this, tr("Fatal Error"),
mediaObject->errorString());
} else {
QMessageBox::warning(this, tr("Error"),
mediaObject->errorString());
}
break;
case Phonon::PlayingState:
playAction->setEnabled(false);
pauseAction->setEnabled(true);
stopAction->setEnabled(true);
//the signal hasVideoChanged(bool) can not emit if the first file played is audio in video UI.
//So, use this workaround to emit a signal which is for checking whether change the UI.
count++;
if(count < 2){
emit changeMediaPlayerUI();
}
break;
case Phonon::StoppedState:
stopAction->setEnabled(false);
playAction->setEnabled(true);
pauseAction->setEnabled(false);
timeLcd->display("00:00");
break;
case Phonon::PausedState:
pauseAction->setEnabled(false);
stopAction->setEnabled(true);
playAction->setEnabled(true);
break;
case Phonon::BufferingState:
break;
default:
;
}
}
void MainWindow::tick(qint64 time)
{
QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
timeLcd->display(displayTime.toString("mm:ss"));
}
void MainWindow::tableClicked(int row, int /* column */)
{
mediaObject->stop();
mediaObject->clearQueue();
if (row >= sources.size())
return;
mediaObject->setCurrentSource(sources[row]);
mediaObject->play();
}
void MainWindow::sourceChanged(const Phonon::MediaSource &source)
{
musicTable->selectRow(sources.indexOf(source));
timeLcd->display("00:00");
}
void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */)
{
if (newState == Phonon::ErrorState) {
QMessageBox::warning(this, tr("Error opening files"),
metaInformationResolver->errorString());
while (!sources.isEmpty() &&
!(sources.takeLast() == metaInformationResolver->currentSource())) {} /* loop */;
return;
}
if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
return;
if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid)
return;
QMap<QString, QString> metaData = metaInformationResolver->metaData();
QString title = metaData.value("TITLE");
QString fileName = metaInformationResolver->currentSource().fileName();
if (title == ""){
title = fileName;
title.remove(0,title.lastIndexOf("/")+1);
title.remove(title.lastIndexOf("."),title.size()-title.lastIndexOf("."));
}
QString artist = metaData.value("ARTIST");
if (artist == ""){
artist = "Unknown";
}
QString album = metaData.value("ALBUM");
if (album == ""){
album = "Unknown";
}
QString year = metaData.value("DATE");
if (year == ""){
year = "Unknown";
}
QTime totalTime(0, (metaInformationResolver->totalTime()/ 60000) % 60, (metaInformationResolver->totalTime()/ 1000) % 60);
QString time = totalTime.toString(("mm:ss"));
if (time == ""){
time = "Unknown";
}
storeDataToDatabase(fileName,title,time,artist,album,year);
QTableWidgetItem *t
基于Qt4 phonon的多媒体播放器
4星 · 超过85%的资源 需积分: 16 152 浏览量
2010-08-25
08:52:45
上传
评论 3
收藏 1.15MB ZIP 举报
yangzhigang531
- 粉丝: 1
- 资源: 2
最新资源
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页