return i;
}
-MediaView::MediaView(QWidget *parent) : QWidget(parent)
+MediaView::MediaView(QWidget *parent) : View(parent)
, stopped(false)
, downloadItem(0)
#ifdef APP_SNAPSHOT
, snapshotSettings(0)
#endif
+ , pauseTime(0)
{ }
void MediaView::initialize() {
SearchParams* MediaView::getSearchParams() {
VideoSource *videoSource = playlistModel->getVideoSource();
if (videoSource && videoSource->metaObject()->className() == QLatin1String("YTSearch")) {
- YTSearch *search = dynamic_cast<YTSearch *>(videoSource);
+ YTSearch *search = qobject_cast<YTSearch *>(videoSource);
return search->getSearchParams();
}
return 0;
#ifdef APP_PHONON
void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
- if (newState == Phonon::PlayingState)
+ if (pauseTime > 0 && (newState == Phonon::PlayingState || newState == Phonon::BufferingState)) {
+ mediaObject->seek(pauseTime);
+ pauseTime = 0;
+ }
+ if (newState == Phonon::PlayingState) {
videoAreaWidget->showVideo();
- else if (newState == Phonon::ErrorState) {
+ } else if (newState == Phonon::ErrorState) {
qWarning() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
if (mediaObject->errorType() == Phonon::FatalError)
handleError(mediaObject->errorString());
switch( mediaObject->state() ) {
case Phonon::PlayingState:
mediaObject->pause();
+ pauseTimer.start();
break;
default:
- mediaObject->play();
+ if (pauseTimer.hasExpired(60000)) {
+ pauseTimer.invalidate();
+ connect(playlistModel->activeVideo(), SIGNAL(gotStreamUrl(QUrl)), SLOT(resumeWithNewStreamUrl(QUrl)));
+ playlistModel->activeVideo()->loadStreamUrl();
+ } else mediaObject->play();
break;
}
#endif
QSlider *slider = MainWindow::instance()->getSlider();
slider->setEnabled(false);
slider->setValue(0);
+#else
+ Phonon::SeekSlider *slider = MainWindow::instance()->getSeekSlider();
#endif
+#ifdef APP_SNAPSHOT
if (snapshotSettings) {
delete snapshotSettings;
snapshotSettings = 0;
}
+#endif
}
const QString & MediaView::getCurrentVideoId() {
slider->setValue(0);
#endif
+#ifdef APP_SNAPSHOT
if (snapshotSettings) {
delete snapshotSettings;
snapshotSettings = 0;
MainWindow::instance()->adjustStatusBarVisibility();
}
+#endif
// see you in gotStreamUrl...
}
#ifdef APP_PHONON
qint64 currentTime = mediaObject->currentTime();
qint64 totalTime = mediaObject->totalTime();
- qDebug() << __PRETTY_FUNCTION__ << currentTime << totalTime;
+ // qDebug() << __PRETTY_FUNCTION__ << currentTime << totalTime;
if (totalTime < 1 || currentTime + 10000 < totalTime) {
// QTimer::singleShot(500, this, SLOT(playbackResume()));
mediaObject->seek(currentTime);
#ifdef APP_PHONON
const qint64 totalTime = mediaObject->totalTime();
const qint64 currentTime = mediaObject->currentTime();
- qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime() << totalTime;
+ // qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime() << totalTime;
// add 10 secs for imprecise Phonon backends (VLC, Xine)
if (currentTime > 0 && currentTime + 10000 < totalTime) {
// mediaObject->seek(currentTime);
if (stopped) return;
#ifdef APP_PHONON
const qint64 currentTime = mediaObject->currentTime();
- qDebug() << __PRETTY_FUNCTION__ << currentTime;
+ // qDebug() << __PRETTY_FUNCTION__ << currentTime;
if (currentTime > 0)
mediaObject->seek(currentTime);
mediaObject->play();
#ifdef APP_PHONON
mediaObject->pause();
#endif
- QDesktopServices::openUrl(video->webpage());
+ QString url = video->webpage() + QLatin1String("&t=") + QString::number(mediaObject->currentTime() / 1000);
+ QDesktopServices::openUrl(url);
}
void MediaView::copyWebPage() {
#endif
QMessageBox msgBox(this);
- msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ msgBox.setIconPixmap(IconUtils::pixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::NAME));
msgBox.setInformativeText(tr("It allows you to test the application and see if it works for you."));
msgBox.setModal(true);
Video* video = playlistModel->activeVideo();
if (!video) return;
DownloadManager::instance()->addItem(video);
- The::globalActions()->value("downloads")->setVisible(true);
+ MainWindow::instance()->showActionInStatusBar(The::globalActions()->value("downloads"), true);
QString message = tr("Downloading %1").arg(video->title());
MainWindow::instance()->showMessage(message);
}
downloadItem->start();
}
+void MediaView::resumeWithNewStreamUrl(const QUrl &streamUrl) {
+ pauseTime = mediaObject->currentTime();
+ mediaObject->setCurrentSource(streamUrl);
+ mediaObject->play();
+
+ Video *video = static_cast<Video *>(sender());
+ if (!video) {
+ qDebug() << "Cannot get sender in" << __PRETTY_FUNCTION__;
+ return;
+ }
+ video->disconnect(this);
+}
+
void MediaView::maybeAdjustWindowSize() {
QSettings settings;
if (settings.value("adjustWindowSize", true).toBool())
QString userId = video->channelId();
if (userId.isEmpty()) return;
bool subscribed = YTChannel::isSubscribed(userId);
- if (subscribed) YTChannel::unsubscribe(userId);
- else YTChannel::subscribe(userId);
+ if (subscribed) {
+ YTChannel::unsubscribe(userId);
+ MainWindow::instance()->showMessage(tr("Unsubscribed from %1").arg(video->channelTitle()));
+ } else {
+ YTChannel::subscribe(userId);
+ MainWindow::instance()->showMessage(tr("Subscribed to %1").arg(video->channelTitle()));
+ }
updateSubscriptionAction(video, !subscribed);
}