SeekSlider::SeekSlider (SourceObject *source, QWidget *parent) : QWidget (parent) , Source_ (source) , IgnoreNextValChange_ (false) , IsPressed_ (false) { Ui_.setupUi (this); connect (source, SIGNAL (currentSourceChanged (AudioSource)), this, SLOT (updateRanges ())); connect (source, SIGNAL (totalTimeChanged (qint64)), this, SLOT (updateRanges ())); connect (source, SIGNAL (tick (qint64)), this, SLOT (handleCurrentPlayTime (qint64))); connect (source, SIGNAL (stateChanged (SourceState, SourceState)), this, SLOT (handleStateChanged ())); connect (Ui_.Slider_, SIGNAL (sliderPressed ()), this, SLOT (handleSliderPressed ())); connect (Ui_.Slider_, SIGNAL (sliderReleased ()), this, SLOT (handleSliderReleased ())); }
void MainWindow::on_pushButton_clicked() { QIODevice *QID; //QID->open( QIODevice::WriteOnly); QBuffer myQB; //QID(myQB); //cb(128000,64000); //dFile.setFileName("../RecordTest.raw"); microphoneBuffer->open( QIODevice::ReadWrite); QAudioFormat format; // Set up the desired format, for example: format.setSampleRate(16000); format.setChannelCount(1); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); if (!info.isFormatSupported(format)) { qWarning() << "Default format not supported, trying to use the nearest."; format = info.nearestFormat(format); } audio = new QAudioInput(format, this); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); //QTimer::singleShot(5000, this, SLOT(on_pushButton_2_clicked())); isRecording = true; audio->start(microphoneBuffer); }
void WavSound::play() { QFile *file = new QFile(fileName); file->open(QIODevice::ReadOnly); QAudioFormat f; readHeader(&f, file); QAudioFormat format = f; QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } //seek(0x4e*4); //...avoiding clicks from the wav files file->seek(0x4e); QAudioOutput *audio = new QAudioOutput(format, NULL); if(file->size()<30000) audio->setBufferSize(10000); audio->setVolume(0.5); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); audio->start(file); }
void AudioCore::recordAudioSample(int t = 500, bool writeToFile = false) { latestSampleDuration = t; writeSampleToFile = writeToFile; sampleAudioBuffer.open(QBuffer::ReadWrite); QAudioFormat format; // Настраиваем желаемый формат, например: format.setSampleRate(AudioCore::SampleRate); format.setSampleSize(8 * AudioCore::SampleSize); format.setChannelCount(1); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); // ВЫбрать устройство ввода 0: QAudioDeviceInfo info(QAudioDeviceInfo::availableDevices(QAudio::AudioInput).at(0)); qDebug() << "Selected input device =" << info.deviceName(); if (!info.isFormatSupported(format)) { qWarning() << "Default format not supported, trying to use the nearest."; format = info.nearestFormat(format); } audio = new QAudioInput(format); // Очень важно, иначе будут шумы и все картинки ужасно некрасивые. audio->setVolume(AudioCore::AudioLevel); connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); QTimer::singleShot(t, this, SLOT(stopRecording())); audio->start(&sampleAudioBuffer); }
AudioPlayer::AudioPlayer(QObject *parent) : QObject(parent), myIsPlaying(false) { m_pMediaPlayer = new QMediaPlayer; connect(m_pMediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(handleStateChanged(QMediaPlayer::State))); }
MediaCall::MediaCall (GlooxAccount *acc, QXmppCall *call) : QObject (call) , Call_ (call) , Account_ (acc) { connect (Call_, SIGNAL (stateChanged (QXmppCall::State)), this, SLOT (handleStateChanged (QXmppCall::State))); }
TransferJob::TransferJob (QXmppTransferJob *job) : QObject (job) , Job_ (job) { connect (Job_, SIGNAL (progress (qint64, qint64)), this, SIGNAL (transferProgress (qint64,qint64))); connect (Job_, SIGNAL (error (QXmppTransferJob::Error)), this, SLOT (handleErrorAppeared (QXmppTransferJob::Error))); connect (Job_, SIGNAL (stateChanged (QXmppTransferJob::State)), this, SLOT (handleStateChanged (QXmppTransferJob::State))); }
CallChatWidget::CallChatWidget (QObject *call, QWidget *parent) : QWidget (parent) , CallObject_ (call) , Call_ (qobject_cast<IMediaCall*> (call)) { Ui_.setupUi (this); Ui_.StatusLabel_->setText (tr ("Initializing...")); connect (call, SIGNAL (destroyed ()), this, SLOT (scheduleDelete ())); connect (call, SIGNAL (stateChanged (LeechCraft::Azoth::IMediaCall::State)), this, SLOT (handleStateChanged (LeechCraft::Azoth::IMediaCall::State))); }
bool QSoundProcessor::open() { this->close(); pt_audioinput = new QAudioInput(m_device_info, m_format, this); connect(pt_audioinput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); pt_buffer = new QBuffer(this); if(pt_buffer->open(QIODevice::ReadWrite)) { connect(pt_buffer, SIGNAL(readyRead()), this, SLOT(dataReady())); pt_audioinput->start(pt_buffer); qWarning() << "current buffersize = " << pt_audioinput->bufferSize(); qWarning() << "current notifyinterval = " << pt_audioinput->notifyInterval() << " ms"; qWarning() << "current samplerate = " << m_format.sampleRate(); qWarning() << "current samplesize = " << m_format.sampleSize(); qWarning() << "current channelcount = " << m_format.channelCount(); qWarning() << "current byteorder = " << m_format.byteOrder(); qWarning() << "current sampletype = " << m_format.sampleType(); return true; } return false; }
CallChatWidget::CallChatWidget (QObject *call, QWidget *parent) : QWidget { parent } , CallObject_ { call } , Call_ { qobject_cast<IMediaCall*> (call) } { Ui_.setupUi (this); Ui_.StatusLabel_->setText (tr ("Initializing...")); if (Call_->GetDirection () == IMediaCall::DOut) Ui_.AcceptButton_->hide (); connect (call, SIGNAL (destroyed ()), this, SLOT (scheduleDelete ())); connect (call, SIGNAL (stateChanged (LeechCraft::Azoth::IMediaCall::State)), this, SLOT (handleStateChanged (LeechCraft::Azoth::IMediaCall::State))); }
PlayerAdaptor::PlayerAdaptor (FDOPropsAdaptor *fdo, Player *player) : QDBusAbstractAdaptor (player) , Props_ (fdo) , Player_ (player) { setAutoRelaySignals (true); connect (Player_, SIGNAL (songChanged (MediaInfo)), this, SLOT (handleSongChanged ())); connect (Player_, SIGNAL (playModeChanged (Player::PlayMode)), this, SLOT (handlePlayModeChanged ())); connect (Player_->GetSourceObject (), SIGNAL (stateChanged (Phonon::State, Phonon::State)), this, SLOT (handleStateChanged ())); connect (Player_->GetAudioOutput (), SIGNAL (volumeChanged (qreal)), this, SLOT (handleVolumeChanged ())); }
// for playing a valid audio file given by the slot // if this function is called by a slot for the first time, audio will be played // if a slot called this function twice in sequence, the currently played // audio will be stopped void Player::play(Slot *givenSlot) { QString filepath = givenSlot->getPath(); QFile audioFile(filepath); // in order to stop playback for the audio file given by the // same slot after calling this function in sequence DURING playback if(givenSlot == lastSlot) stop(); else { stop(); lastSlot = givenSlot; // some basic checks: // 1. check audio file (*.wav ending AND subsistence) if(!filepath.endsWith(".wav", Qt::CaseInsensitive)) { // if the given file is not valid, you don't have to call this // function twice in order to play a (new set) valid file if(lastSlot != NULL) lastSlot = NULL; throw QString("The given audio file is no *.wav!"); } if(!audioFile.exists()) throw QString("The given audio file does not exist!"); // 2. check if format is supported by the audio device if(!device.isFormatSupported(format)) throw QString("Raw audio format not supported by back-end, cannot play audio."); // if audio is currently playing - stop it stop(); // prepare audio playback player = new QAudioOutput(device, format); player->setNotifyInterval(500); connect(player, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); //connect(player, SIGNAL(notify()), this, SLOT(displayCurrentDuration())); // read audio data if(audioFile.open(QIODevice::ReadOnly)) { // read out wav info // ######### IMPLEMENTATION ######### audioFile.seek(44); // skip wav header audioData = audioFile.readAll(); audioFile.close(); audioBuffer.setBuffer(&audioData); audioBuffer.open(QIODevice::ReadOnly); // prepare/open buffer for playback lastSlot->setStatus(SlotStatus::PLAYING); // start playback thread player->start(&audioBuffer); qDebug() << ">> Audio has been started."; } } }
/*! Opens a new network session. */ void ConnectionManager::openNewNetworkSession() { qDebug() << "ConnectionManager::openNewNetworkSession() =>"; if (mState == Connecting) { qDebug() << "ConnectionManager::openNewNetworkSession()" << "<= Already connecting!!!"; return; } // Disconnect previous connection and delete the network session instance. disconnect(); clearConnectionInformation(); delete mNetworkSession; mNetworkSession = 0; // Set state to 'Connecting'. setState(Connecting); // Get the configurations. QList<QNetworkConfiguration> configurations = mNetworkConfMgr->allConfigurations(QNetworkConfiguration::Discovered); if (configurations.isEmpty()) { configurations << mNetworkConfMgr->defaultConfiguration(); } bool sessionOpened(false); foreach (QNetworkConfiguration configuration, configurations) { if (!validWlanConfiguration(configuration)) { // Invalid configuration, try the next one. continue; } // Valid configuration found! mNetworkSession = new QNetworkSession(configuration, this); // Open the network session. mNetworkSession->open(); if (mNetworkSession->waitForOpened()) { qDebug() << "ConnectionManager::openNewNetworkSession():" << "Selecting" << configuration.name(); // Connect the signals. connect(mNetworkSession, SIGNAL(closed()), this, SLOT(handleNetworkSessionClosed()), Qt::UniqueConnection); connect(mNetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(handleError(QNetworkSession::SessionError)), Qt::UniqueConnection); connect(mNetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(handleNewConfigurationActivated()), Qt::UniqueConnection); connect(mNetworkSession, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(handleStateChanged(QNetworkSession::State)), Qt::UniqueConnection); handleNetworkSessionOpened(); sessionOpened = true; break; } else { qDebug() << "ConnectionManager::openNewNetworkSession():" << "Failed to open" << configuration.name() << ":" << mNetworkSession->errorString(); delete mNetworkSession; mNetworkSession = 0; } } if (!sessionOpened) { qDebug() << "ConnectionManager::openNewNetworkSession():" << "No valid session opened!"; setState(Failed); } qDebug() << "ConnectionManager::openNewNetworkSession() <="; }
void StelVideoMgr::loadVideo(const QString& filename, const QString& id, const float x, const float y, const bool show, const float alpha) { if (videoObjects.contains(id)) { qWarning() << "[StelVideoMgr] Video object with ID" << id << "already exists, dropping it"; dropVideo(id); } videoObjects[id] = new VideoPlayer; videoObjects[id]->videoItem= new QGraphicsVideoItem(); // This sets a tiny size so that if window should appear before proper resize, it should not disturb. videoObjects[id]->videoItem->setSize(QSizeF(1,1)); videoObjects[id]->player = new QMediaPlayer(0, QMediaPlayer::VideoSurface); videoObjects[id]->duration=-1; // -1 to signal "unknown". videoObjects[id]->resolution=QSize(); // initialize with "invalid" empty resolution, we must detect this when player is starting! videoObjects[id]->keepVisible=false; videoObjects[id]->needResize=true; // resolution and target frame not yet known. videoObjects[id]->simplePlay=true; videoObjects[id]->targetFrameSize=QSizeF(); // start with invalid, depends on parameters given in playVideo(), playPopoutVideo() and resolution detected only after playing started. videoObjects[id]->popupOrigin=QPointF(); videoObjects[id]->popupTargetCenter=QPointF(); videoObjects[id]->player->setProperty("Stel_id", id); // allow tracking of log messages and access of members. videoObjects[id]->player->setVideoOutput(videoObjects[id]->videoItem); videoObjects[id]->videoItem->setOpacity(alpha); #ifndef Q_OS_WIN // There is a notable difference: on Windows this causes a crash. On Linux, it is required, else the movie frame is visible before proper resize. videoObjects[id]->videoItem->setVisible(show); #endif videoObjects[id]->lastPos=-1; // A few connections are not really needed, they are signals we don't use. TBD: Remove or keep commented out? connect(videoObjects[id]->player, SIGNAL(bufferStatusChanged(int)), this, SLOT(handleBufferStatusChanged(int))); connect(videoObjects[id]->player, SIGNAL(durationChanged(qint64)), this, SLOT(handleDurationChanged(qint64))); // (CRITICALLY IMPORTANT!) connect(videoObjects[id]->player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(handleError(QMediaPlayer::Error))); connect(videoObjects[id]->player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(handleMediaStatusChanged(QMediaPlayer::MediaStatus))); //connect(videoObjects[id]->player, SIGNAL(positionChanged(qint64)), this, SLOT(handlePositionChanged(qint64))); // we test isSeekable() where needed, so only debug log entry. --> And we may use the signal however now during blocking load below! connect(videoObjects[id]->player, SIGNAL(seekableChanged(bool)), this, SLOT(handleSeekableChanged(bool))); connect(videoObjects[id]->player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(handleStateChanged(QMediaPlayer::State))); connect(videoObjects[id]->player, SIGNAL(videoAvailableChanged(bool)), this, SLOT(handleVideoAvailableChanged(bool))); connect(videoObjects[id]->player, SIGNAL(audioAvailableChanged(bool)), this, SLOT(handleAudioAvailableChanged(bool))); connect(videoObjects[id]->player, SIGNAL(mutedChanged(bool)), this, SLOT(handleMutedChanged(bool))); connect(videoObjects[id]->player, SIGNAL(volumeChanged(int)), this, SLOT(handleVolumeChanged(int))); connect(videoObjects[id]->player, SIGNAL(availabilityChanged(bool)), this, SLOT(handleAvailabilityChanged(bool))); connect(videoObjects[id]->player, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)), this, SLOT(handleAvailabilityChanged(QMultimedia::AvailabilityStatus))); // Only this is triggered also on Windows. Lets us read resolution etc. (CRITICALLY IMPORTANT!) connect(videoObjects[id]->player, SIGNAL(metaDataChanged()), this, SLOT(handleMetaDataChanged())); // That signal would require less overhead, but is not triggered under Windows and apparently also not on MacOS X. (QTBUG-42034.) // If this becomes available/bugfixed, it should be preferred as being more elegant. // connect(videoObjects[id]->player, SIGNAL(metaDataChanged(QString,QVariant)), this, SLOT(handleMetaDataChanged(QString,QVariant))); // We need an absolute pathname here. QMediaContent content(QUrl::fromLocalFile(QFileInfo(filename).absoluteFilePath())); videoObjects[id]->player->setMedia(content); if (verbose) { qDebug() << "Loading " << content.canonicalUrl(); qDebug() << "Media Resources queried from player:"; qDebug() << "\tSTATUS: " << videoObjects[id]->player->mediaStatus(); qDebug() << "\tFile: " << videoObjects[id]->player->currentMedia().canonicalUrl(); } // qDebug() << "scene->addItem..."; StelMainView::getInstance().scene()->addItem(videoObjects[id]->videoItem); // qDebug() << "scene->addItem OK"; videoObjects[id]->videoItem->setPos(x, y); // DEFAULT SIZE: show a tiny frame. This gets updated to native resolution as soon as resolution becomes known. Needed? //videoObjects[id]->videoItem->setSize(QSizeF(1, 1)); // after many troubles with incompletely loaded files we attempt a blocking load from https://wiki.qt.io/Seek_in_Sound_File // This may be no longer required. But please keep the block here for testing/reactivation if necessary. // if (! videoObjects[id]->player->isSeekable()) // { // qDebug() << "Not Seekable!"; // if (verbose) // qDebug() << "Blocking load ..."; // QEventLoop loop; // QTimer timer; // qDebug() << "Not Seekable: setSingleShot"; // timer.setSingleShot(true); // timer.setInterval(5000); // 5 seconds, may be too long? // qDebug() << "Not Seekable: connect..."; // loop.connect(&timer, SIGNAL (timeout()), &loop, SLOT (quit()) ); // loop.connect(videoObjects[id]->player, SIGNAL (seekableChanged(bool)), &loop, SLOT (quit())); // qDebug() << "Not Seekable: loop..."; // loop.exec(); // if (verbose) // qDebug() << "Blocking load finished, should be seekable now or 5s are over."; // } if (verbose) qDebug() << "Loaded video" << id << "for pos " << x << "/" << y << "Size" << videoObjects[id]->videoItem->size(); videoObjects[id]->player->setPosition(0); // This should force triggering a metadataAvailable() with resolution update. if (show) videoObjects[id]->player->play(); else videoObjects[id]->player->pause(); }
void FtpClient::init() { qDebug() << "FtpClient:: " << port << " Init"; // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); qDebug() << "FtpClient:: " << port << " Init connect"; // from abtractsocket connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(handleError(QAbstractSocket::SocketError))); connect(tcpSocket, SIGNAL(connected()), this, SLOT(handleConnected())); connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(handleDisconnected())); connect(tcpSocket, SIGNAL(hostFound()), this, SLOT(handleHostFound())); connect(tcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)), this, SLOT(handleProxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*))); connect(tcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(handleStateChanged(QAbstractSocket::SocketState))); // from QIODevice connect(tcpSocket, SIGNAL(aboutToClose()), this, SLOT(handleAboutToClose())); connect(tcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(handleBytesWritten(qint64))); connect(tcpSocket, SIGNAL(readChannelFinished()), this, SLOT(handleReadChannelFinished())); connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(handleReadyRead())); qDebug() << "FtpClient:: " << port << " Init NetworkConfigurationManager manager"; QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { qDebug() << "FtpClient::Init QNetworkConfigurationManager::NetworkSessionRequired"; // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String(SETTING_STR)); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } qDebug() << "FtpClient:: " << port << " Init new QNetworkSession(config, this)"; networkSession = new QNetworkSession(config, this); qDebug() << "FtpClient:: " << port << " Init connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()))"; connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened())); qDebug() << "FtpClient:: " << port << " Init networkSession->open()"; networkSession->open(); } else { qDebug() << "FtpClient:: Init " << port << " tcpSocket->connectToHost())" << " ipAddress " << ipAddress << " port " << port; tcpSocket->connectToHost(QHostAddress(ipAddress), port); } mInitiated = true; }
void MainWindow::init() { Expects(!windowHandle()); createWinId(); initHook(); updateWindowIcon(); connect(windowHandle(), &QWindow::activeChanged, this, [this] { handleActiveChanged(); }, Qt::QueuedConnection); connect(windowHandle(), &QWindow::windowStateChanged, this, [this](Qt::WindowState state) { handleStateChanged(state); }); _positionUpdatedTimer->setSingleShot(true); connect(_positionUpdatedTimer, SIGNAL(timeout()), this, SLOT(savePositionByTimer())); updatePalette(); if ((_title = Platform::CreateTitleWidget(this))) { _title->init(); } initSize(); updateUnreadCounter(); }