#ifdef APP_DEMO
demoTimer = new QTimer(this);
demoTimer->setSingleShot(true);
- demoTimer->setInterval(60000);
connect(demoTimer, SIGNAL(timeout()), SLOT(demoMessage()));
#endif
void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
this->mediaObject = mediaObject;
Phonon::createPath(this->mediaObject, videoWidget);
- connect(mediaObject, SIGNAL(finished()), this, SLOT(skip()));
+ connect(mediaObject, SIGNAL(finished()), this, SLOT(playbackFinished()));
connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
this, SLOT(stateChanged(Phonon::State, Phonon::State)));
connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
this, SLOT(currentSourceChanged(Phonon::MediaSource)));
- connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
+ // connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
}
void MediaView::search(SearchParams *searchParams) {
if (separator > 0 && separator + 1 < keyword.length()) {
display = keyword.mid(separator+1);
}
- }
+
+ // also hide sidebar
+ playlistWidget->hide();
+ } else playlistWidget->show();
// tr("You're watching \"%1\"").arg(searchParams->keywords())
}
}
void MediaView::handleError(QString message) {
+ // if (message.indexOf("movie atom") != -1 || message.indexOf("Could not open") != -1) {
+ QTimer::singleShot(1000, this, SLOT(startPlaying()));
+ return;
+ // }
+
+ /*
videoAreaWidget->showError(message);
skippedVideo = listModel->activeVideo();
// recover from errors by skipping to the next video
errorTimer->start(2000);
+ */
}
void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/)
break;
case Phonon::PlayingState:
- //qDebug("playing");
+ // qDebug("playing");
videoAreaWidget->showVideo();
break;
case Phonon::StoppedState:
- //qDebug("stopped");
+ // qDebug("stopped");
// play() has already been called when setting the source
// but Phonon on Linux needs a little more help to start playback
- if (!reallyStopped) mediaObject->play();
+ // if (!reallyStopped) mediaObject->play();
#ifdef APP_MAC
// Workaround for Mac playback start problem
if (!timerPlayFlag) {
- workaroundTimer->start();
+ // workaroundTimer->start();
}
#endif
break;
case Phonon::PausedState:
- //qDebug("paused");
+ qDebug("paused");
break;
case Phonon::BufferingState:
- //qDebug("buffering");
+ qDebug("buffering");
break;
case Phonon::LoadingState:
- //qDebug("loading");
+ qDebug("loading");
break;
default:
errorTimer->stop();
listView->selectionModel()->clearSelection();
if (downloadItem) {
+ downloadItem->stop();
delete downloadItem;
downloadItem = 0;
}
mediaObject->pause();
if (downloadItem) {
+ downloadItem->stop();
delete downloadItem;
downloadItem = 0;
}
}
video->disconnect(this);
+
QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
+#ifdef Q_WS_X11
+ QString tempFile = tempDir + "/minitube-" + getenv("USERNAME") + ".mp4";
+#else
QString tempFile = tempDir + "/minitube.mp4";
- if (!QFile::remove(tempFile)) {
+#endif
+ if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
qDebug() << "Cannot remove temp file";
}
Video *videoCopy = video->clone();
- if (downloadItem) delete downloadItem;
+ if (downloadItem) {
+ downloadItem->stop();
+ delete downloadItem;
+ }
downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
// connect(downloadItem, SIGNAL(progress(int)), SLOT(downloadProgress(int)));
+ connect(downloadItem, SIGNAL(bufferProgress(int)), loadingWidget, SLOT(bufferStatus(int)));
// connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
+ connect(video, SIGNAL(errorStreamUrl(QString)), SLOT(handleError(QString)));
+ connect(downloadItem, SIGNAL(error(QString)), SLOT(handleError(QString)));
downloadItem->start();
}
startPlaying();
break;
case Starting:
- qDebug() << "Starting";
+ // qDebug() << "Starting";
break;
case Finished:
- qDebug() << "Finished";
+ // qDebug() << "Finished" << mediaObject->state();
+ // if (mediaObject->state() == Phonon::StoppedState) startPlaying();
break;
case Failed:
- qDebug() << "Failed";
+ // qDebug() << "Failed";
case Idle:
- qDebug() << "Idle";
+ // qDebug() << "Idle";
break;
}
}
void MediaView::startPlaying() {
if (reallyStopped) return;
+ if (!downloadItem) {
+ skip();
+ return;
+ }
// go!
qDebug() << "Playing" << downloadItem->currentFilename();
}
#ifdef APP_DEMO
- demoTimer->start();
+ demoTimer->start(30000);
#endif
}
listModel->setActiveRow(nextRow);
}
+void MediaView::playbackFinished() {
+ // qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime();
+ // add 10 secs for imprecise Phonon backends (VLC, Xine)
+ if (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) {
+ // mediaObject->seek(mediaObject->currentTime());
+ QTimer::singleShot(3000, this, SLOT(playbackResume()));
+ } else skip();
+}
+
+void MediaView::playbackResume() {
+ mediaObject->seek(mediaObject->currentTime());
+ mediaObject->play();
+}
+
void MediaView::openWebPage() {
Video* video = listModel->activeVideo();
if (!video) return;
if (mediaObject->state() != Phonon::PlayingState) return;
mediaObject->pause();
- QMessageBox msgBox;
+ QMessageBox msgBox(this);
msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::APP_NAME));
msgBox.setInformativeText(tr("It allows you to test the application and see if it works for you."));
msgBox.setModal(true);
+ // make it a "sheet" on the Mac
+ msgBox.setWindowModality(Qt::WindowModal);
QPushButton *quitButton = msgBox.addButton(tr("Continue"), QMessageBox::RejectRole);
QPushButton *buyButton = msgBox.addButton(tr("Get the full version"), QMessageBox::ActionRole);
QDesktopServices::openUrl(QString(Constants::WEBSITE) + "#download");
} else {
mediaObject->play();
+ demoTimer->start(300000);
}
}
#endif