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 if(!m_pParameters->GetName().isEmpty())
28 ui->leName->setText(m_pParameters->GetName());
30 foreach(
auto ai, QMediaDevices::audioInputs())
32 ui->cmbAudioInput->addItem(ai.description());
34 ui->gbAudioInput->setCheckable(
true);
35 if(QMediaDevices::audioInputs().size() > 0)
36 ui->gbAudioInput->setChecked(m_pParameters->GetEnableAudioInput());
38 ui->gbAudioInput->setEnabled(
false);
39 ui->gbAudioInput->setChecked(
false);
41 if(m_pParameters->GetAudioInput() != -1)
42 ui->cmbAudioInput->setCurrentIndex(m_pParameters->GetAudioInput());
43 ui->cbAudioInputMuted->setChecked(m_pParameters->GetAudioInputMuted());
44 ui->dsAudioInputVolume->setValue(m_pParameters->GetAudioInputVolume());
46 foreach(
auto ao, QMediaDevices::audioOutputs())
47 ui->cmbAudioOutput->addItem(ao.description());
48 ui->gbAudioOutput->setCheckable(
true);
49 if(QMediaDevices::audioOutputs().size() > 0)
50 ui->gbAudioOutput->setChecked(m_pParameters->GetEnableAudioOutput());
52 ui->gbAudioOutput->setEnabled(
false);
53 ui->gbAudioOutput->setChecked(
false);
55 if(m_pParameters->GetAudioOutput() != -1)
56 ui->cmbAudioOutput->setCurrentIndex(m_pParameters->GetAudioOutput());
57 ui->cbAudioOutputMuted->setCheckable(
true);
58 ui->cbAudioOutputMuted->setChecked(m_pParameters->GetAudioOutputMuted());
59 ui->dsAudioOutputVolume->setValue(m_pParameters->GetAudioOutputVolume());
61 if(QMediaDevices::videoInputs().size() > 0)
63 ui->cmbType->addItem(tr(
"Camera"), (
int)CParameterPlayer::TYPE::Camera);
64 foreach(
const QCameraDevice &cameraDevice, QMediaDevices::videoInputs()) {
65 ui->cmbCamera->addItem(cameraDevice.description());
67 if(m_pParameters->GetCamera() > -1)
68 ui->cmbCamera->setCurrentIndex(m_pParameters->GetCamera());
71 ui->cmbType->addItem(tr(
"Url"), (
int)CParameterPlayer::TYPE::Url);
72 ui->leUrl->setText(m_pParameters->GetUrl());
74 int nIndex = ui->cmbType->findData((
int)m_pParameters->GetType());
76 ui->cmbType->setCurrentIndex(nIndex);
77 on_cmbType_currentIndexChanged(nIndex);
81 m_pRecordUI->SetParameter(&m_pParameters->m_Record);
82 ui->tabWidget->addTab(m_pRecordUI, m_pRecordUI->windowIcon(), m_pRecordUI->windowTitle());
85CDlgPlayer::~CDlgPlayer()
90void CDlgPlayer::accept()
94 if(!ui->leName->text().isEmpty())
95 m_pParameters->SetName(ui->leName->text());
96 if((ui->cmbType->currentData().value<CParameterPlayer::TYPE>()
97 == CParameterPlayer::TYPE::Url) && ui->leUrl->text().isEmpty()) {
98 ui->leUrl->setFocus();
99 ui->tabWidget->setCurrentIndex(0);
100 QString szErr = tr(
"The url is empty. please set!");
101 QMessageBox::critical(
this, tr(
"Error"), szErr);
102 qCritical(log) << szErr;
107 ui->tabWidget->setCurrentWidget(m_pRecordUI);
111 m_pParameters->SetType(
112 ui->cmbType->currentData().value<CParameterPlayer::TYPE>());
113 m_pParameters->SetUrl(ui->leUrl->text());
114 m_pParameters->SetCamera(ui->cmbCamera->currentIndex());
115 switch(m_pParameters->GetType()) {
116 case CParameterPlayer::TYPE::Camera: {
117 int nIndex = m_pParameters->GetCamera();
118 if(-1 < nIndex && nIndex < QMediaDevices::videoInputs().size())
119 if(ui->leName->text().isEmpty())
120 m_pParameters->SetName(
122 + QMediaDevices::videoInputs().at(nIndex).description());
125 case CParameterPlayer::TYPE::Url:
126 QFileInfo fi(m_pParameters->GetUrl());
127 if(ui->leName->text().isEmpty())
128 m_pParameters->SetName(tr(
"Url: ") + fi.fileName());
132 m_pParameters->SetEnableAudioInput(ui->gbAudioInput->isChecked());
133 m_pParameters->SetAudioInput(ui->cmbAudioInput->currentIndex());
134 m_pParameters->SetAudioInputMuted(ui->cbAudioInputMuted->isChecked());
135 m_pParameters->SetAudioInputVolume(ui->dsAudioInputVolume->value());
136 m_pParameters->SetEnableAudioOutput(ui->gbAudioOutput->isChecked());
137 m_pParameters->SetAudioOutput(ui->cmbAudioOutput->currentIndex());
138 m_pParameters->SetAudioOutputMuted(ui->cbAudioOutputMuted->isChecked());
139 m_pParameters->SetAudioOutputVolume(ui->dsAudioOutputVolume->value());
141 nRet = m_pRecordUI->Accept();
148void CDlgPlayer::on_cmbType_currentIndexChanged(
int index)
150 ui->cmbCamera->setVisible(
false);
151 ui->leUrl->setVisible(
false);
152 ui->pbUrlBrowse->setVisible(
false);
154 CParameterPlayer::TYPE type
155 = (CParameterPlayer::TYPE)ui->cmbType->itemData(index).toInt();
157 case CParameterPlayer::TYPE::Camera:
158 ui->cmbCamera->setVisible(
true);
159 ui->gbAudioInput->setChecked(
true);
161 case CParameterPlayer::TYPE::Url:
162 ui->leUrl->setVisible(
true);
163 ui->pbUrlBrowse->setVisible(
true);
164 ui->gbAudioInput->setChecked(
false);
171void CDlgPlayer::on_pbUrlBrowse_clicked()
180 QString szFilter(tr(
"Media files(* wmv *.aac *.WebM *.mtk *.ogg *.mp4 *.mov *.avi);;All files(*.*)"));
181 QString szFile = QFileDialog::getOpenFileName(
182 this, tr(
"Open file"),
183 QStandardPaths::writableLocation(QStandardPaths::MoviesLocation),
185 if(!szFile.isEmpty())
186 ui->leUrl->setText(szFile);
virtual bool CheckValidity(bool validity=false)
Check parameters validity.