日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt播放器常用设置

發(fā)布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt播放器常用设置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

播放效果

?

1.pro文件增加項

......

QT += multimedia multimediawidgets

........

2.頭文件

? ? ?void init();

void positionChanged(qint64 position); void durationChanged(qint64 duration); void on_playButton_clicked(); void updateDurationInfo(qint64 currentInfo); void on_treeView_player_doubleClicked(const QModelIndex &index);//這個是綁定文件雙擊打開,當然也可以修改成打開本地文件播放的形式。

3. .cpp文件 (UI->調的控件都要在ui界面里設置好,再布置其他控件)

void MainWindow::init() {//視頻文件 appPath=QCoreApplication::applicationDirPath(); model = new QFileSystemModel(); model->setRootPath(appPath); videoPath=appPath+"/player"; ui->treeView_player->setModel(model); ui->treeView_player->setRootIndex(model->index(videoPath)); m_mediaPlayer=new QMediaPlayer(ui->widget_player,QMediaPlayer::VideoSurface); //視頻播放 m_mediaPlayer=new QMediaPlayer(ui->widget_player,QMediaPlayer::VideoSurface); videoWidget = new QVideoWidget; videoWidget->setAspectRatioMode(Qt::IgnoreAspectRatio); playList=new QMediaPlaylist; //播放器布局 QVBoxLayout *layout=new QVBoxLayout; layout->addWidget(videoWidget); ui->widget_player->setLayout(layout); videoWidget->setPalette(Qt::black); ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); //滑塊設置 ui->m_positionSlider->setRange(0, m_mediaPlayer->duration() / 1000); connect(ui->m_positionSlider, &QSlider::sliderMoved, this, &MainWindow::seek); ui->label_time->hide(); } void MainWindow::initConnect() //連接slide和時間(快進 快退) { connect(m_mediaPlayer,SIGNAL(durationChanged(qint64)),this,SLOT(durationChanged(qint64))); connect(m_mediaPlayer,SIGNAL(positionChanged(qint64)),this,SLOT(positionChanged(qint64))); } void MainWindow::on_playButton_clicked() //播放暫停按鈕 { if(m_mediaPlayer->state()==QMediaPlayer::PlayingState){ m_mediaPlayer->pause(); ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); //播放時顯示播放按鈕 } else { m_mediaPlayer->play(); ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); //暫停時顯示播放按鈕 } } void MainWindow::on_treeView_player_doubleClicked(const QModelIndex &index) //視頻目錄雙擊 { //如果是文件夾 返回 if(model->isDir(index)){ return; } QString path=model->filePath(index); playList->clear();//清空列表 playList->addMedia(QUrl::fromLocalFile(path)); m_mediaPlayer->setPlaylist(playList); m_mediaPlayer->setVideoOutput(videoWidget); m_mediaPlayer->play(); if(m_mediaPlayer->state()==QMediaPlayer::PlayingState){ ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); ui->label_time->show(); } } void MainWindow::durationChanged(qint64 duration) //視頻時間設置 { m_duration = duration / 1000; ui->m_positionSlider->setMaximum((int)duration/1000); } void MainWindow::positionChanged(qint64 progress) //滑塊設置 { //if (!m_positionSlider->isSliderDown()) ui-> m_positionSlider->setValue((int)progress / 1000); updateDurationInfo(progress / 1000); } void MainWindow::updateDurationInfo(qint64 currentInfo) // slide時間顯示格式設置 { QString tStr; if (currentInfo || m_duration) { QTime currentTime((currentInfo / 3600) % 60, (currentInfo / 60) % 60, currentInfo % 60, (currentInfo * 1000) % 1000); QTime totalTime((m_duration / 3600) % 60, (m_duration / 60) % 60, m_duration % 60, (m_duration * 1000) % 1000); QString format = "mm:ss"; if (m_duration > 3600) format = "hh:mm:ss"; tStr = currentTime.toString(format) + " / " + totalTime.toString(format); } ui->label_time->setText(tStr); } void MainWindow::seek(int seconds) //滑塊視頻快進快退等 { m_mediaPlayer->setPosition(seconds * 1000); // m_mediaPlayer->play(); }

一些包含文件使用ctrl+enter可添加,或自己在幫助上查找添加等都可。

頭文件或者pro文件有些地方可能不完善,方法還湊活能用。

?

總結

以上是生活随笔為你收集整理的Qt播放器常用设置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。