玉兔远程控制 0.0.31
载入中...
搜索中...
未找到
DlgPlayer.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QCamera>
4#include <QCameraDevice>
5#include <QMediaDevices>
6#include <QAudioDevice>
7#include <QFileDialog>
8#include <QStandardPaths>
9#include <QMediaRecorder>
10#include <QMediaFormat>
11#include <QLoggingCategory>
12#include <QScreen>
13#include <QGuiApplication>
14#include <QMessageBox>
15
16#include "DlgPlayer.h"
17#include "ui_DlgPlayer.h"
18
19static Q_LOGGING_CATEGORY(log, "Player.Connect")
20CDlgPlayer::CDlgPlayer(CParameterPlayer *pPara, QWidget *parent)
21 : QDialog(parent)
22 , ui(new Ui::CDlgPlayer)
23 , m_pParameters(pPara)
24{
25 ui->setupUi(this);
26
27 foreach(auto ai, QMediaDevices::audioInputs())
28 {
29 ui->cmbAudioInput->addItem(ai.description());
30 }
31 ui->gbAudioInput->setCheckable(true);
32 if(QMediaDevices::audioInputs().size() > 0)
33 ui->gbAudioInput->setChecked(m_pParameters->GetEnableAudioInput());
34 else {
35 ui->gbAudioInput->setEnabled(false);
36 ui->gbAudioInput->setChecked(false);
37 }
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());
42
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());
48 else {
49 ui->gbAudioOutput->setEnabled(false);
50 ui->gbAudioOutput->setChecked(false);
51 }
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());
57
58 if(QMediaDevices::videoInputs().size() > 0)
59 {
60 ui->cmbType->addItem(tr("Camera"), (int)CParameterPlayer::TYPE::Camera);
61 foreach(const QCameraDevice &cameraDevice, QMediaDevices::videoInputs()) {
62 ui->cmbCamera->addItem(cameraDevice.description());
63 }
64 if(m_pParameters->GetCamera() > -1)
65 ui->cmbCamera->setCurrentIndex(m_pParameters->GetCamera());
66 }
67
68 ui->cmbType->addItem(tr("Url"), (int)CParameterPlayer::TYPE::Url);
69 ui->leUrl->setText(m_pParameters->GetUrl());
70
71 int nIndex = ui->cmbType->findData((int)m_pParameters->GetType());
72 if(-1 < nIndex) {
73 ui->cmbType->setCurrentIndex(nIndex);
74 on_cmbType_currentIndexChanged(nIndex);
75 }
76
77 m_pRecordUI = new CParameterRecordUI(ui->tabWidget);
78 m_pRecordUI->SetParameter(&m_pParameters->m_Record);
79 ui->tabWidget->addTab(m_pRecordUI, m_pRecordUI->windowIcon(), m_pRecordUI->windowTitle());
80}
81
82CDlgPlayer::~CDlgPlayer()
83{
84 delete ui;
85}
86
87void CDlgPlayer::accept()
88{
89 int nRet = 0;
90
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;
98 return;
99 }
100
101 if(!m_pRecordUI->CheckValidity(true)) {
102 ui->tabWidget->setCurrentWidget(m_pRecordUI);
103 return;
104 }
105
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(
115 tr("Camera: ")
116 + QMediaDevices::videoInputs().at(nIndex).description());
117 break;
118 }
119 case CParameterPlayer::TYPE::Url:
120 QFileInfo fi(m_pParameters->GetUrl());
121 m_pParameters->SetName(tr("Url: ") + fi.fileName());
122 break;
123 }
124
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());
133
134 nRet = m_pRecordUI->Accept();
135 if(nRet)
136 return;
137
138 QDialog::accept();
139}
140
141void CDlgPlayer::on_cmbType_currentIndexChanged(int index)
142{
143 ui->cmbCamera->setVisible(false);
144 ui->leUrl->setVisible(false);
145 ui->pbUrlBrowse->setVisible(false);
146
147 CParameterPlayer::TYPE type
148 = (CParameterPlayer::TYPE)ui->cmbType->itemData(index).toInt();
149 switch(type) {
150 case CParameterPlayer::TYPE::Camera:
151 ui->cmbCamera->setVisible(true);
152 ui->gbAudioInput->setChecked(true);
153 break;
154 case CParameterPlayer::TYPE::Url:
155 ui->leUrl->setVisible(true);
156 ui->pbUrlBrowse->setVisible(true);
157 ui->gbAudioInput->setChecked(false);
158 break;
159 default:
160 break;
161 }
162}
163
164void CDlgPlayer::on_pbUrlBrowse_clicked()
165{
166 /*
167 QMediaRecorder recorder;
168 auto formats = recorder.mediaFormat().supportedFileFormats(QMediaFormat::Decode);
169 qDebug(log) << "Support file formats:" << formats;
170 foreach(auto f, formats) {
171 qDebug(log) << "File format name:" << QMediaFormat::fileFormatName(f);
172 } //*/
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),
177 szFilter);
178 if(!szFile.isEmpty())
179 ui->leUrl->setText(szFile);
180}
virtual bool CheckValidity(bool validity=false)
检查参数的有效性