4#include <QCameraDevice>
5#include <QMediaDevices>
8#include <QStandardPaths>
9#include <QMediaRecorder>
10#include <QMediaFormat>
11#include <QLoggingCategory>
13#include <QGuiApplication>
17#include "ui_DlgPlayer.h"
19static Q_LOGGING_CATEGORY(log,
"Player.Connect")
23 , m_pParameters(pPara)
27 foreach(
auto ai, QMediaDevices::audioInputs())
29 ui->cmbAudioInput->addItem(ai.description());
31 ui->gbAudioInput->setCheckable(
true);
32 if(QMediaDevices::audioInputs().size() > 0)
33 ui->gbAudioInput->setChecked(m_pParameters->GetEnableAudioInput());
35 ui->gbAudioInput->setEnabled(
false);
36 ui->gbAudioInput->setChecked(
false);
38 if(m_pParameters->GetAudioInput() != -1)
39 ui->cmbAudioInput->setCurrentIndex(m_pParameters->GetAudioInput());
40 ui->cbAudioInputMuted->setChecked(m_pParameters->GetAudioInputMuted());
41 ui->dsAudioInputVolume->setValue(m_pParameters->GetAudioInputVolume());
43 foreach(
auto ao, QMediaDevices::audioOutputs())
44 ui->cmbAudioOutput->addItem(ao.description());
45 ui->gbAudioOutput->setCheckable(
true);
46 if(QMediaDevices::audioOutputs().size() > 0)
47 ui->gbAudioOutput->setChecked(m_pParameters->GetEnableAudioOutput());
49 ui->gbAudioOutput->setEnabled(
false);
50 ui->gbAudioOutput->setChecked(
false);
52 if(m_pParameters->GetAudioOutput() != -1)
53 ui->cmbAudioOutput->setCurrentIndex(m_pParameters->GetAudioOutput());
54 ui->cbAudioOutputMuted->setCheckable(
true);
55 ui->cbAudioOutputMuted->setChecked(m_pParameters->GetAudioOutputMuted());
56 ui->dsAudioOutputVolume->setValue(m_pParameters->GetAudioOutputVolume());
58 if(QMediaDevices::videoInputs().size() > 0)
60 ui->cmbType->addItem(tr(
"Camera"), (
int)CParameterPlayer::TYPE::Camera);
61 foreach(
const QCameraDevice &cameraDevice, QMediaDevices::videoInputs()) {
62 ui->cmbCamera->addItem(cameraDevice.description());
64 if(m_pParameters->GetCamera() > -1)
65 ui->cmbCamera->setCurrentIndex(m_pParameters->GetCamera());
68 ui->cmbType->addItem(tr(
"Url"), (
int)CParameterPlayer::TYPE::Url);
69 ui->leUrl->setText(m_pParameters->GetUrl());
71 int nIndex = ui->cmbType->findData((
int)m_pParameters->GetType());
73 ui->cmbType->setCurrentIndex(nIndex);
74 on_cmbType_currentIndexChanged(nIndex);
78 m_pRecordUI->SetParameter(&m_pParameters->m_Record);
79 ui->tabWidget->addTab(m_pRecordUI, m_pRecordUI->windowIcon(), m_pRecordUI->windowTitle());
82CDlgPlayer::~CDlgPlayer()
87void CDlgPlayer::accept()
91 if((ui->cmbType->currentData().value<CParameterPlayer::TYPE>()
92 == CParameterPlayer::TYPE::Url) && ui->leUrl->text().isEmpty()) {
93 ui->leUrl->setFocus();
94 ui->tabWidget->setCurrentIndex(0);
95 QString szErr = tr(
"The url is empty. please set!");
96 QMessageBox::critical(
this, tr(
"Error"), szErr);
97 qCritical(log) << szErr;
102 ui->tabWidget->setCurrentWidget(m_pRecordUI);
106 m_pParameters->SetType(
107 ui->cmbType->currentData().value<CParameterPlayer::TYPE>());
108 m_pParameters->SetUrl(ui->leUrl->text());
109 m_pParameters->SetCamera(ui->cmbCamera->currentIndex());
110 switch(m_pParameters->GetType()) {
111 case CParameterPlayer::TYPE::Camera: {
112 int nIndex = m_pParameters->GetCamera();
113 if(-1 < nIndex && nIndex < QMediaDevices::videoInputs().size())
114 m_pParameters->SetName(
116 + QMediaDevices::videoInputs().at(nIndex).description());
119 case CParameterPlayer::TYPE::Url:
120 QFileInfo fi(m_pParameters->GetUrl());
121 m_pParameters->SetName(tr(
"Url: ") + fi.fileName());
125 m_pParameters->SetEnableAudioInput(ui->gbAudioInput->isChecked());
126 m_pParameters->SetAudioInput(ui->cmbAudioInput->currentIndex());
127 m_pParameters->SetAudioInputMuted(ui->cbAudioInputMuted->isChecked());
128 m_pParameters->SetAudioInputVolume(ui->dsAudioInputVolume->value());
129 m_pParameters->SetEnableAudioOutput(ui->gbAudioOutput->isChecked());
130 m_pParameters->SetAudioOutput(ui->cmbAudioOutput->currentIndex());
131 m_pParameters->SetAudioOutputMuted(ui->cbAudioOutputMuted->isChecked());
132 m_pParameters->SetAudioOutputVolume(ui->dsAudioOutputVolume->value());
134 nRet = m_pRecordUI->Accept();
141void CDlgPlayer::on_cmbType_currentIndexChanged(
int index)
143 ui->cmbCamera->setVisible(
false);
144 ui->leUrl->setVisible(
false);
145 ui->pbUrlBrowse->setVisible(
false);
147 CParameterPlayer::TYPE type
148 = (CParameterPlayer::TYPE)ui->cmbType->itemData(index).toInt();
150 case CParameterPlayer::TYPE::Camera:
151 ui->cmbCamera->setVisible(
true);
152 ui->gbAudioInput->setChecked(
true);
154 case CParameterPlayer::TYPE::Url:
155 ui->leUrl->setVisible(
true);
156 ui->pbUrlBrowse->setVisible(
true);
157 ui->gbAudioInput->setChecked(
false);
164void CDlgPlayer::on_pbUrlBrowse_clicked()
173 QString szFilter(tr(
"Media files(* wmv *.aac *.WebM *.mtk *.ogg *.mp4 *.mov *.avi);;All files(*.*)"));
174 QString szFile = QFileDialog::getOpenFileName(
175 this, tr(
"Open file"),
176 QStandardPaths::writableLocation(QStandardPaths::MoviesLocation),
178 if(!szFile.isEmpty())
179 ui->leUrl->setText(szFile);
virtual bool CheckValidity(bool validity=false)
检查参数的有效性