Status SoundManager::loadSound(SoundClip* soundClip, QString strSoundFile) { Q_ASSERT(soundClip); if (!QFile::exists(strSoundFile)) { return Status::FILE_NOT_FOUND; } if (strSoundFile.isEmpty()) { return Status::FAIL; } QString strCopyFile = editor()->object()->copyFileToDataFolder(strSoundFile); Q_ASSERT(!strCopyFile.isEmpty()); soundClip->init(strCopyFile); soundClip->setSoundClipName(QFileInfo(strSoundFile).fileName()); Status st = createMediaPlayer(soundClip); if (!st.ok()) { delete soundClip; return st; } return Status::OK; }
/** * \brief Set the media file * @param filePath as the media file path */ void UBMediaWidget::setFile(const QString &filePath) { Q_ASSERT("" != filePath); mFilePath = filePath; mpMediaObject = new Phonon::MediaObject(this); mpMediaObject->setTickInterval(TICK_INTERVAL); connect(mpMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State))); connect(mpMediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(onTotalTimeChanged(qint64))); connect(mpMediaObject, SIGNAL(tick(qint64)), this, SLOT(onTick(qint64))); mpMediaObject->setCurrentSource(Phonon::MediaSource(filePath)); createMediaPlayer(); }
Status SoundManager::loadSound(Layer* soundLayer, int frameNumber, QString strSoundFile) { Q_ASSERT(soundLayer); if (soundLayer->type() != Layer::SOUND) { return Status::ERROR_INVALID_LAYER_TYPE; } if (frameNumber < 0) { return Status::ERROR_INVALID_FRAME_NUMBER; } if (!QFile::exists(strSoundFile)) { return Status::FILE_NOT_FOUND; } KeyFrame* key = soundLayer->getKeyFrameAt(frameNumber); if (key == nullptr) { key = new SoundClip; soundLayer->addKeyFrame(frameNumber, key); } if (!key->fileName().isEmpty()) { // file path should be empty. // we can only load a audio clip to an empty key! return Status::FAIL; } QString strCopyFile = soundLayer->object()->copyFileToDataFolder(strSoundFile); Q_ASSERT(!strCopyFile.isEmpty()); QString sOriginalName = QFileInfo(strSoundFile).fileName(); SoundClip* soundClip = dynamic_cast<SoundClip*>(key); soundClip->init(strCopyFile); soundClip->setSoundClipName(sOriginalName); Status st = createMediaPlayer(soundClip); if (!st.ok()) { delete soundClip; return st; } return Status::OK; }
Status SoundManager::processSound(SoundClip* soundClip) { Q_ASSERT(soundClip); if (!QFile::exists(soundClip->fileName())) { return Status::FILE_NOT_FOUND; } soundClip->init(soundClip->fileName()); Status st = createMediaPlayer(soundClip); if (!st.ok()) { return st; } return Status::OK; }
Status SoundManager::load(Object* obj) { int count = obj->getLayerCount(); for (int i = 0; i < count; ++i) { Layer* layer = obj->getLayer(i); if (layer->type() != Layer::SOUND) { continue; } LayerSound* soundLayer = static_cast<LayerSound*>(layer); soundLayer->foreachKeyFrame([this](KeyFrame* key) { SoundClip* clip = dynamic_cast<SoundClip*>(key); Q_ASSERT(clip); createMediaPlayer(clip); }); } return Status::OK; }