您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 基于Linux的音频播放器的设计源代码
嵌入式操作系统课程设计源代码设计题目:基于Linux的音频播放器的设计院系:*********班级:********组别:第1组学号:******姓名:起止日期:2012年6月11日~2012年6月15日指导教师:#####includeqplayer.h#includeQtGui#includeui_qplayer.h#includectime#includeQVariantQPlayer::QPlayer(QWidget*parent):QMainWindow(parent),ui(newUi::QPlayer){audioOutput=newPhonon::AudioOutput(Phonon::MusicCategory,this);//初始化系列变量mediaObject=newPhonon::MediaObject(this);metaInformationResolver=newPhonon::MediaObject(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(constPhonon::MediaSource&)),this,SLOT(sourceChanged(constPhonon::MediaSource&)));connect(mediaObject,SIGNAL(aboutToFinish()),this,SLOT(aboutToFinish()));Phonon::createPath(mediaObject,audioOutput);setupActions();ui-setupUi(this);ui-seekSlider-setMediaObject(mediaObject);ui-volumeSlider-setAudioOutput(audioOutput);ui-volumeSlider-setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);QPalettepalette;palette.setBrush(QPalette::Light,Qt::darkGray);ui-lcdNumber-setPalette(palette);QStringListheaders;headerstr(标题)tr(作者)tr(唱片)tr(年代);ui-tableWidget-setHorizontalHeaderLabels(headers);ui-tableWidget-setSelectionMode(QAbstractItemView::SingleSelection);ui-tableWidget-setSelectionBehavior(QAbstractItemView::SelectRows);connect(ui-tableWidget,SIGNAL(cellPressed(int,int)),this,SLOT(tableClicked(int,int)));ui-lcdNumber-display(00:00);ui-PauseButton-hide();}QPlayer::~QPlayer(){deleteui;}voidQPlayer::changeEvent(QEvent*e){QMainWindow::changeEvent(e);switch(e-type()){caseQEvent::LanguageChange:ui-retranslateUi(this);break;default:break;}}voidQPlayer::setupActions(){playAction=newQAction(style()-standardIcon(QStyle::SP_MediaPlay),tr(Play),this);playAction-setShortcut(tr(Crl+P));playAction-setDisabled(true);pauseAction=newQAction(style()-standardIcon(QStyle::SP_MediaPause),tr(Pause),this);pauseAction-setShortcut(tr(Ctrl+A));pauseAction-setDisabled(true);stopAction=newQAction(style()-standardIcon(QStyle::SP_MediaStop),tr(Stop),this);stopAction-setShortcut(tr(Ctrl+S));stopAction-setDisabled(true);nextAction=newQAction(style()-standardIcon(QStyle::SP_MediaSkipForward),tr(Next),this);nextAction-setShortcut(tr(Ctrl+N));previousAction=newQAction(style()-standardIcon(QStyle::SP_MediaSkipBackward),tr(Previous),this);previousAction-setShortcut(tr(Ctrl+R));addFilesAction=newQAction(tr(Add&Files),this);addFilesAction-setShortcut(tr(Ctrl+F));connect(playAction,SIGNAL(triggered()),mediaObject,SLOT(play()));connect(pauseAction,SIGNAL(triggered()),mediaObject,SLOT(pause()));connect(stopAction,SIGNAL(triggered()),mediaObject,SLOT(stop()));connect(addFilesAction,SIGNAL(triggered()),this,SLOT(addFiles()));}voidQPlayer::addFiles(){QStringListfiles=QFileDialog::getOpenFileNames(this,tr(选择音乐文件),QDesktopServices::storageLocation(QDesktopServices::MusicLocation));if(files.isEmpty())return;intindex=sources.size();foreach(QStringstring,files){Phonon::MediaSourcesource(string);sources.append(source);}if(!sources.isEmpty())metaInformationResolver-setCurrentSource(sources.at(index));}//显示歌曲名字voidQPlayer::tableClicked(introw,int){boolwasPlaying=mediaObject-state()==Phonon::PlayingState;mediaObject-stop();mediaObject-clearQueue();if(row=sources.size())return;mediaObject-setCurrentSource(sources[row]);if(wasPlaying)mediaObject-play();elsemediaObject-stop();}//显示歌曲时间voidQPlayer::tick(qint64time){QTimedisplayTime(0,(time/60000)%60,(time/1000)%60);ui-lcdNumber-display(displayTime.toString(mm:ss));}voidQPlayer::sourceChanged(constPhonon::MediaSource&source){ui-tableWidget-selectRow(sources.indexOf(source));ui-lcdNumber-display(00:00);}voidQPlayer::metaStateChanged(Phonon::StatenewState,Phonon::State){if(newState==Phonon::ErrorState){QMessageBox::warning(this,tr(文件格式错误),metaInformationResolver-errorString());while(!sources.isEmpty()&&!(sources.takeLast()==metaInformationResolver-currentSource())){};return;}if(newState!=Phonon::StoppedState&&newState!=Phonon::PausedState)return;if(metaInformationResolver-currentSource().type()==Phonon::MediaSource::Invalid)return;QMapQString,QStringmetaData=metaInformationResolver-metaData();QStringtitle=metaData.value(TITLE);if(title==)title=metaInformationResolver-currentSource().fileName();QTableWidgetItem*titleItem=newQTableWidgetItem(title);titleItem-setFlags(titleItem-flags()^Qt::ItemIsEditable);QTableWidgetItem*artistItem=newQTableWidgetItem(metaData.value(ARTIST));artistItem-setFlags(artistItem-flags()^Qt::ItemIsEditable);QTableWidgetItem*albumItem=newQTableWidgetItem(metaData.value(ALBUM));albumItem-setFlags(albumItem-flags()^Qt::ItemIsEditable);QTableWidgetItem*yearItem=newQTableWidgetItem(metaData.value(DATE));yearI
本文标题:基于Linux的音频播放器的设计源代码
链接地址:https://www.777doc.com/doc-2570414 .html