Permalink
Browse files

MythBrowser: Add a new MythFlashPlayer class that evaluates JavaScrip…

…t in order

to control video playback. Current available controls are play, pause, and seek.
It will be used for better flash player integration in MythNetvision once the
scripts are updated to pass the required mythflash:// urls.

Patch by Jonatan <mythtv@comhem.se>. Refs #9301.
  • Loading branch information...
1 parent a95968d commit 55ca0d1843fa4ef501c024d8c6153e1af4ddf536 Paul Harrison committed Dec 6, 2010
@@ -0,0 +1,98 @@
+#include <stdlib.h>
+#include <iostream>
+
+// qt
+#include <QApplication>
+#include <QEvent>
+
+// myth
+#include <mythverbose.h>
+#include <mythcontext.h>
+#include <libmythui/mythmainwindow.h>
+#include <mythuiwebbrowser.h>
+
+// mythbrowser
+#include "webpage.h"
+#include "mythflashplayer.h"
+
+using namespace std;
+
+MythFlashPlayer::MythFlashPlayer(MythScreenStack *parent,
+ QStringList &urlList)
+ : MythScreenType (parent, "mythflashplayer"),
+ m_browser(NULL), m_url(urlList[0])
+{
+ qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
+}
+
+
+MythFlashPlayer::~MythFlashPlayer()
+{
+ qApp->restoreOverrideCursor();
+
+ if (m_browser)
+ {
+ m_browser->disconnect();
+ DeleteChild(m_browser);
+ m_browser = NULL;
+ }
+}
+
+bool MythFlashPlayer::Create(void)
+{
+ m_browser = new MythUIWebBrowser(this, "mythflashplayer");
+ m_browser->SetArea(GetMythMainWindow()->GetUIScreenRect());
+ m_browser->Init();
+ m_browser->SetActive(true);
+ m_browser->Show();
+
+ BuildFocusList();
+
+ SetFocusWidget(m_browser);
+
+ m_url.replace("mythflash://", "http://");
+ VERBOSE(VB_GENERAL, QString("Opening %1").arg(m_url));
+ m_browser->LoadPage(QUrl::fromEncoded(m_url.toLocal8Bit()));
+
+ return true;
+}
+
+QVariant MythFlashPlayer::evaluateJavaScript(const QString& source)
+{
+ return m_browser->evaluateJavaScript(source);
+}
+
+bool MythFlashPlayer::keyPressEvent(QKeyEvent *event)
+{
+ QStringList actions;
+ bool handled = GetMythMainWindow()->TranslateKeyPress("TV Playback", event, actions);
+
+ for (int i = 0; i < actions.size() && !handled; i++)
+ {
+ QString action = actions[i];
+ handled = true;
+
+ if (action == "PAUSE")
+ evaluateJavaScript("play();");
+ else if (action == "SEEKFFWD")
+ evaluateJavaScript("seek(10);");
+ else if (action == "SEEKRWND")
+ evaluateJavaScript("seek(-10);");
+ else if (action == "CHANNELUP")
+ evaluateJavaScript("seek(60);");
+ else if (action == "CHANNELDOWN")
+ evaluateJavaScript("seek(-60);");
+ else
+ handled = false;
+
+ if (handled)
+ return true;
+ }
+
+ handled = m_browser->keyPressEvent(event);
+
+ if (!handled && MythScreenType::keyPressEvent(event))
+ handled = true;
+
+ return handled;
+}
@@ -0,0 +1,25 @@
+#ifndef MYTHFLASHPLAYER_H
+#define MYTHFLASHPLAYER_H
+
+#include <mythscreentype.h>
+
+class MythUIWebBrowser;
+
+class MythFlashPlayer : public MythScreenType
+{
+ Q_OBJECT
+
+ public:
+ MythFlashPlayer(MythScreenStack *parent, QStringList &urlList);
+ ~MythFlashPlayer();
+
+ bool Create(void);
+ bool keyPressEvent(QKeyEvent *);
+
+ private:
+ QVariant evaluateJavaScript(const QString&);
+ MythUIWebBrowser* m_browser;
+ QString m_url;
+};
+
+#endif

0 comments on commit 55ca0d1

Please sign in to comment.