⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mediarecorder.cpp

📁 Qtopia下的多媒体录音源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    // Shut down recording or playback.    if (contentsWidget != NULL)    {        stopEverythingNoSwitch();        // Disable the "Play" and "Delete" buttons so that if we        // are restarted in "fast load" mode, we will return to        // the initial "nothing is recorded" state in the UI.        setReplayEnabled(false);        setReplayEnabled(false);    }    // Determine if we should return to the file selector screen,    // or exit from the application.    if (stack->currentWidget() == selector)    {        e->accept();    }    else if (requestMode)    {	// The user did not record any sounds during the request.        QCopEnvelope qcop( responseChannel, "valueSupplied(QString,QString)" );        qcop << responseId << QString();        requestMode = false;        e->accept();    }    else    {        switchToFileSelector();        e->ignore();    }}void MediaRecorder::keyPressEvent( QKeyEvent *e ){#ifdef QTOPIA_PHONE    if (e->key() == Qt::Key_Select)    {        if (playing)            stopPlaying();        else if (recording)            stopRecording();        else            startRecording();        e->accept();        return;    }#endif    QMainWindow::keyPressEvent(e);}void MediaRecorder::audioOutputDone(){    // Read the next block of samples.    long samplesRead = 0;    if ( samplesRead <= 0 ) {	stopPlaying();	return;    }    // Update the waveform display.    contents->waveform->newSamples( sampleBuffer, samplesRead );    // Update the playback time if another second has elapsed.    samplesPlayed += samplesRead;#ifdef QTOPIA4_TODO    long newTime = samplesPlayed / (long)(decoder->audioFrequency( 0 ));    if ( newTime != recordTime ) {	recordTime = newTime;	if ( recordTime > contents->progress->maximum() ) {	    recordTime = contents->progress->maximum();	}	contents->progress->setValue( (int)recordTime );    }#endif}void MediaRecorder::traySocket( const QString& msg, const QByteArray &data ){    QDataStream stream( data );    int         id = 0;    QPoint      p;    if (msg == "popup(int,QPoint)" )    {        stream >> id >> p;    }    else if ( msg == "clicked(int,QPoint)" || msg == "doubleClicked(int,QPoint)" )    {        stream >> id >> p;    }    if (id == RECORD_LIGHT_ID )    {        if (this->isVisible())            this->raise();        else            this->showMaximized();    }}void MediaRecorder::setContextKey( bool record ){#ifdef QTOPIA_PHONE    if ( record )        QSoftMenuBar::setLabel( contents->recordButton, Qt::Key_Select, "mediarecorder/record", tr("Record") );    else        QSoftMenuBar::setLabel( contents->recordButton, Qt::Key_Select, "mediarecorder/stop", tr("Stop") );#else    Q_UNUSED(record);#endif}void MediaRecorder::setReplayEnabled( bool flag ){    contents->replayButton->setEnabled( flag );}void MediaRecorder::setDeleteEnabled( bool flag ){    contents->deleteButton->setEnabled( flag );}void MediaRecorder::documentSelected(const QContent& doc){    stopEverythingNoSwitch();    lastSaved = doc.file();    m_sound = new QSound( lastSaved );    m_sound->play();    playing = true;}void MediaRecorder::newSelected(){    if (recorderPlugins == NULL)        recorderPlugins = new MediaRecorderPluginList();    if (m_sound != NULL)        // stop playing    {        delete m_sound;        m_sound = NULL;    }    switchToRecorder();}void MediaRecorder::appMessage( const QString& msg, const QByteArray& data ){    QString chan;    QString id, mimeType, formatTag;    int     frequency, channels;    // Parameters to "getAudio" message:    //    //	    QString	Name of the QCop channel to send the reply on.    //	    QString	Unique id.    //	    QString	MIME type of the requested format.    //	    QString	Requested sub-format (e.g. "pcm", "amr", etc).    //	    int		Frequency to record with.    //	    int		Number of channels to record with.    //    // The mediarecorder will eventually respond with the message    // "valueSupplied(QString,QString)", indicating the ID and the    // name of the file    // containing the recording.  If the user quit the recorder without    // recording a sound, then the filename will be empty.    //    // Note: it is conceivable that something will go wrong and the    // response will never be sent (e.g. app crash).  Applications that    // request recording functionality should not rely upon getting    // an answer back.    //    if (msg == "getAudio(QString,QString,QString,QString,int,int)") {        // Decode the parameters to the message.        QDataStream stream(data);        stream >> chan;        stream >> id;        stream >> mimeType;        stream >> formatTag;        stream >> frequency;        stream >> channels;        // Stop existing recording or playback sessions.        stopEverythingNoSwitch();        // Copy the parameters into place.        responseChannel = chan;        responseId = id;        recordQuality.frequency = frequency;        recordQuality.channels = channels;        recordQuality.mimeType = mimeType;        recordQuality.formatTag = formatTag;        requestMode = true;        // Switch to the recording mode.        switchToRecorder();        // Make sure that the app keeps running.        QtopiaApplication::setKeepRunning();    }}void MediaRecorder::toggleRecording(){    if ( playing )        stopPlayingNoSwitch();    switchToRecorder();    recordClicked();}void MediaRecorder::switchToFileSelector(){#ifndef QTOPIA_PHONE    menu->hide();#endif    stack->setCurrentIndex( stack->indexOf( selector ) );    configureAction->setEnabled( false );}void MediaRecorder::switchToOther(){    stack->setCurrentIndex(stack->indexOf(getContentsWidget()));}void MediaRecorder::switchToRecorder(){    switchToOther();    setContextKey(true);    setReplayEnabled(false);    setDeleteEnabled(false);    configureAction->setEnabled(true);#ifndef QTOPIA_PHONE    if (requestMode)    {        contents->GroupBox1->hide();        contents->GroupBox2->hide();        menu->hide();        configureAction->setEnabled( false );    }    else    {        if (smallScreen)            contents->GroupBox1->hide();        else            contents->GroupBox1->show();        contents->GroupBox2->show();        menu->show();    }#endif    contents->recordButton->show();    contents->replayButton->hide();    contents->deleteButton->hide();    contents->waveform->reset();    contents->recordButton->setFocus();}void MediaRecorder::switchToPlayback(){    switchToOther();    setContextKey( false );    setReplayEnabled( true );    setDeleteEnabled( false );    configureAction->setEnabled( false );#ifndef QTOPIA_PHONE    contents->GroupBox1->hide();    contents->GroupBox2->hide();    menu->hide();#endif    contents->replayButton->show();    contents->recordButton->hide();    contents->deleteButton->hide();    contents->waveform->reset();    contents->recordButton->setFocus();}void MediaRecorder::stopEverythingNoSwitch(){    if (recording)    {        stopRecordingNoSwitch();    }    else if (playing)    {        stopPlayingNoSwitch();    }}QWidget* MediaRecorder::getContentsWidget(){    if (contentsWidget == NULL)    {        // contents (buttons & graph)        contentsWidget = new QWidget(stack);        contents = new Ui::MediaRecorderBase();        contents->setupUi(contentsWidget);        QFileSystemFilter *fsf = new QFileSystemFilter;        fsf->documents = QFileSystemFilter::Set;        contents->storageLocation->setFilter(fsf);        stack->addWidget( contentsWidget );        // other init        initializeContents();        // Hook up interesting signals.        connect(contents->recordButton,                SIGNAL(clicked()),                this,                SLOT(recordClicked()));        // menu        QMenu* options;#ifdef QTOPIA_PHONE        // Create the context menu for the record/playback screen.        options = QSoftMenuBar::menuFor(contentsWidget);#else        QToolBar *bar = new QToolBar( this );        addToolBar( bar );        bar->setMovable( false );        menu = bar;        QMenuBar *mb = new QMenuBar( bar );        options = mb->addMenu( tr( "Options" ) );#endif        configureAction = new QAction(QIcon(":icon/settings"), tr( "Settings..."), this);        connect(configureAction, SIGNAL(triggered()), this, SLOT(configure()));        configureAction->setWhatsThis(tr("Configure the recording quality settings."));        configureAction->setEnabled(true);        options->addAction(configureAction);        // GUI opts#ifdef QTOPIA_PHONE        // Don't display the buttons in Qtopia Phone Edition, because        // they take up too much screen real estate and have confusing        // key navigation behaviours.        //contents->recordButton->hide();        contents->replayButton->hide();        contents->deleteButton->hide();        // Make the context key say "Record".        setContextKey(true);#else        connect(contents->replayButton,                SIGNAL(clicked()),                this,                SLOT(replayClicked()));        connect(contents->deleteButton,                SIGNAL(clicked()),                this,                SLOT(deleteClicked()));#endif    }    return contentsWidget;}/*!    \service VoiceRecordingService VoiceRecording    \brief Provides the Qtopia VoiceRecording service.    The \i VoiceRecording service enables applications to toggle    audio recording on or off.*//*!    \internal*/VoiceRecordingService::~VoiceRecordingService(){}/*!    Toggle audio recording on or off.    This slot corresponds to the QCop service message    \c{VoiceRecording::toggleRecording()}.*/void VoiceRecordingService::toggleRecording(){    parent->toggleRecording();    QtopiaApplication::setKeepRunning();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -