summaryrefslogtreecommitdiffstats
path: root/tests/manual/mediaplayer
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/mediaplayer')
-rw-r--r--tests/manual/mediaplayer/CMakeLists.txt30
-rw-r--r--tests/manual/mediaplayer/doc/images/activeqt-mediaplayer-example.jpgbin0 -> 48753 bytes
-rw-r--r--tests/manual/mediaplayer/doc/src/mediaplayer.qdoc64
-rw-r--r--tests/manual/mediaplayer/main.cpp145
-rw-r--r--tests/manual/mediaplayer/mainwindow.ui147
-rw-r--r--tests/manual/mediaplayer/mediaaxwidget.h29
-rw-r--r--tests/manual/mediaplayer/mediaplayer.pro11
7 files changed, 426 insertions, 0 deletions
diff --git a/tests/manual/mediaplayer/CMakeLists.txt b/tests/manual/mediaplayer/CMakeLists.txt
new file mode 100644
index 0000000..6f443e7
--- /dev/null
+++ b/tests/manual/mediaplayer/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## mediaplayer Binary:
+#####################################################################
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTOUIC ON)
+
+qt_internal_add_manual_test(tst_mediaplayer
+ SOURCES
+ mainwindow.ui
+ mediaaxwidget.h
+ main.cpp
+ INCLUDE_DIRECTORIES
+ ../shared
+ LIBRARIES
+ Qt::AxContainer
+ Qt::Core
+ Qt::Gui
+ Qt::Widgets
+)
+
+set_target_properties(tst_mediaplayer PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
diff --git a/tests/manual/mediaplayer/doc/images/activeqt-mediaplayer-example.jpg b/tests/manual/mediaplayer/doc/images/activeqt-mediaplayer-example.jpg
new file mode 100644
index 0000000..4839242
--- /dev/null
+++ b/tests/manual/mediaplayer/doc/images/activeqt-mediaplayer-example.jpg
Binary files differ
diff --git a/tests/manual/mediaplayer/doc/src/mediaplayer.qdoc b/tests/manual/mediaplayer/doc/src/mediaplayer.qdoc
new file mode 100644
index 0000000..e6cd19b
--- /dev/null
+++ b/tests/manual/mediaplayer/doc/src/mediaplayer.qdoc
@@ -0,0 +1,64 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \example activeqt/mediaplayer
+ \title Media Player Example (ActiveQt)
+ \ingroup activeqt-examples
+
+ \brief The Media Player example uses the Microsoft Media Player
+ ActiveX control to implement a functional media player application.
+
+ \image activeqt-mediaplayer-example.jpg
+
+ \e {Media Player} demonstrates how a Qt application can communicate with
+ embedded ActiveX controls using signals, slots, and the \c dynamicCall()
+ function.
+
+ \quotefromfile activeqt/mediaplayer/main.cpp
+ \skipto class MainWindow
+ \printuntil /^\}/
+
+ The \c MainWindow class declares a \c QMainWindow based user interface,
+ using the \c Ui::MainWindow class created by Qt Designer. A number
+ of slots are implemented to handle events from user interface elements,
+ including the \c mediaPlayer object, which is a QAxWidget hosting
+ the Microsoft Media Player ActiveX control.
+
+ \quotefromfile activeqt/mediaplayer/main.cpp
+ \skipto MainWindow::MainWindow()
+ \printuntil /^\}/
+
+ The constructor initializes the user interface, restores a previously
+ saved window geometry, and uses the \c dynamicCall() function to invoke
+ the APIs implemented by the Microsoft Media Player ActiveX control,
+ to set initial configuration parameters.
+
+ \quotefromfile activeqt/mediaplayer/main.cpp
+ \skipto MainWindow::on_mediaPlayer_PlayStateChange
+ \printuntil /^\}/
+
+ The \c on_mediaPlayer_PlayStateChange slot handles the signal emitted
+ by the \c mediaPlayer object when its state changes.
+
+ \quotefromfile activeqt/mediaplayer/main.cpp
+ \skipto MainWindow::openMedia
+ \printuntil /^\}/
+
+ The \c openMedia() function allows a media file to be opened by using
+ the \c dynamicCall() function to set the URL property in the ActiveX
+ control, which causes the media file to be loaded and played.
+
+ \quotefromfile activeqt/mediaplayer/main.cpp
+ \skipto int main
+ \printuntil /^\}/
+
+ The \c main() function starts the application using standard Qt APIs
+ and uses an optional command line argument as the name of a media
+ file to be loaded by the player.
+
+ To build the example, you must first build the QAxContainer
+ library. Then run your make tool in
+ \c examples/activeqt/mediaplayer and run the resulting
+ \c mediaplayer.exe.
+*/
diff --git a/tests/manual/mediaplayer/main.cpp b/tests/manual/mediaplayer/main.cpp
new file mode 100644
index 0000000..955d666
--- /dev/null
+++ b/tests/manual/mediaplayer/main.cpp
@@ -0,0 +1,145 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QApplication>
+#include <QMessageBox>
+#include <QMainWindow>
+#include <QScreen>
+#include <QVariant>
+#include <QSettings>
+#include <QFileDialog>
+#include <QCommandLineParser>
+
+#include "ui_mainwindow.h"
+
+static const char geometryKey[] = "Geometry";
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+public:
+ MainWindow();
+ ~MainWindow();
+ void openMedia(const QString &mediaUrl);
+
+public slots:
+ void on_mediaPlayer_PlayStateChange(int newState);
+ void on_actionOpen_triggered();
+ void on_actionExit_triggered();
+ void on_actionAbout_triggered();
+ void on_actionAboutQt_triggered();
+
+private:
+ void updateWindowTitle(const QString &state);
+ Ui::MainWindow m_ui;
+};
+
+MainWindow::MainWindow()
+{
+ m_ui.setupUi(this);
+
+ QSettings settings(QSettings::IniFormat, QSettings::UserScope,
+ QCoreApplication::organizationName(), QCoreApplication::applicationName());
+
+ const QByteArray restoredGeometry = settings.value(QLatin1String(geometryKey)).toByteArray();
+ if (restoredGeometry.isEmpty() || !restoreGeometry(restoredGeometry)) {
+ const QRect availableGeometry = screen()->availableGeometry();
+ const QSize size = (availableGeometry.size() * 4) / 5;
+ resize(size);
+ move(availableGeometry.center() - QPoint(size.width(), size.height()) / 2);
+ }
+
+ m_ui.mediaPlayer->dynamicCall("enableContextMenu", false);
+ m_ui.mediaPlayer->dynamicCall("stretchToFit", true);
+ updateWindowTitle("");
+}
+
+MainWindow::~MainWindow()
+{
+ QSettings settings(QSettings::IniFormat, QSettings::UserScope,
+ QCoreApplication::organizationName(), QCoreApplication::applicationName());
+ settings.setValue(QLatin1String(geometryKey), saveGeometry());
+}
+
+void MainWindow::on_mediaPlayer_PlayStateChange(int newState)
+{
+ static const QHash<int, const char *> stateMapping {
+ {1, "Stopped"},
+ {2, "Paused"},
+ {3, "Playing"},
+ {4, "Scanning Forwards"},
+ {5, "Scanning Backwards"},
+ {6, "Buffering"},
+ {7, "Waiting"},
+ {8, "Media Ended"},
+ {9, "Transitioning"},
+ {10, "Ready"},
+ {11, "Reconnecting"},
+ };
+ const char *stateStr = stateMapping.value(newState, "");
+ updateWindowTitle(tr(stateStr));
+}
+
+void MainWindow::on_actionOpen_triggered()
+{
+ QFileDialog fileDialog(this, tr("Open File"));
+ fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
+ fileDialog.setFileMode(QFileDialog::ExistingFile);
+ fileDialog.setMimeTypeFilters({ "application/octet-stream", "video/x-msvideo", "video/mp4", "audio/mpeg", "audio/mp4" });
+ if (fileDialog.exec() == QDialog::Accepted)
+ openMedia(fileDialog.selectedFiles().first());
+}
+
+void MainWindow::on_actionExit_triggered()
+{
+ QCoreApplication::quit();
+}
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this, tr("About Media Player"),
+ tr("This Example has been created using the ActiveQt integration into Qt Designer.\n"
+ "It demonstrates the use of QAxWidget to embed the Windows Media Player ActiveX\n"
+ "control into a Qt application."));
+}
+
+void MainWindow::on_actionAboutQt_triggered()
+{
+ QMessageBox::aboutQt(this, tr("About Qt"));
+}
+
+void MainWindow::openMedia(const QString &mediaUrl)
+{
+ if (!mediaUrl.isEmpty())
+ m_ui.mediaPlayer->dynamicCall("URL", mediaUrl);
+}
+
+void MainWindow::updateWindowTitle(const QString &state)
+{
+ QString appName = QCoreApplication::applicationName();
+ QString title = state.isEmpty() ? appName :
+ QString("%1 (%2)").arg(appName, state);
+ setWindowTitle(title);
+}
+
+#include "main.moc"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCoreApplication::setApplicationName(QLatin1String("Active Qt Media Player"));
+ QCoreApplication::setOrganizationName(QLatin1String("QtProject"));
+
+ MainWindow w;
+ QCommandLineParser parser;
+ parser.setApplicationDescription(QCoreApplication::applicationName());
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("file", "The media file to open.");
+ parser.process(app);
+ if (!parser.positionalArguments().isEmpty())
+ w.openMedia(parser.positionalArguments().constFirst());
+ w.show();
+ return app.exec();
+}
diff --git a/tests/manual/mediaplayer/mainwindow.ui b/tests/manual/mediaplayer/mainwindow.ui
new file mode 100644
index 0000000..b83d392
--- /dev/null
+++ b/tests/manual/mediaplayer/mainwindow.ui
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>794</width>
+ <height>599</height>
+ </rect>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="windowTitle">
+ <string>Qt Media Player</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QHBoxLayout" name="unnamed">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QFrame" name="Frame">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <layout class="QVBoxLayout" name="unnamed">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>1</number>
+ </property>
+ <property name="topMargin">
+ <number>1</number>
+ </property>
+ <property name="rightMargin">
+ <number>1</number>
+ </property>
+ <property name="bottomMargin">
+ <number>1</number>
+ </property>
+ <item>
+ <widget class="MediaAxWidget" name="mediaPlayer">
+ <property name="control" stdset="0">
+ <string>{6bf52a52-394a-11d3-b153-00c04f79faa6}</string>
+ </property>
+ <property name="sizePolicy" stdset="0">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>794</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="PopupMenu">
+ <property name="title">
+ <string>&amp;File</string>
+ </property>
+ <addaction name="actionOpen"/>
+ <addaction name="actionExit"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ <addaction name="actionAboutQt"/>
+ </widget>
+ <addaction name="PopupMenu"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <action name="actionOpen">
+ <property name="text">
+ <string>&amp;Open</string>
+ </property>
+ </action>
+ <action name="actionExit">
+ <property name="text">
+ <string>E&amp;xit</string>
+ </property>
+ </action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>&amp;About</string>
+ </property>
+ </action>
+ <action name="actionAboutQt">
+ <property name="text">
+ <string>About &amp;Qt</string>
+ </property>
+ </action>
+ <actiongroup name="FileNewGroup"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>QAxWidget</class>
+ <extends>QWidget</extends>
+ <header>qaxwidget.h</header>
+ </customwidget>
+ <customwidget>
+ <class>MediaAxWidget</class>
+ <extends>QAxWidget</extends>
+ <header>mediaaxwidget.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/manual/mediaplayer/mediaaxwidget.h b/tests/manual/mediaplayer/mediaaxwidget.h
new file mode 100644
index 0000000..f12cdfc
--- /dev/null
+++ b/tests/manual/mediaplayer/mediaaxwidget.h
@@ -0,0 +1,29 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef MEDIAAXWIDGET_H
+#define MEDIAAXWIDGET_H
+
+#include <QtAxContainer/QAxWidget>
+#include <qt_windows.h>
+
+// Overrides the translateKeyEvent() function to pass keystrokes
+// to the Windows Media Player ActiveX control.
+class MediaAxWidget : public QAxWidget
+{
+public:
+ MediaAxWidget(QWidget *parent = nullptr, Qt::WindowFlags f = {})
+ : QAxWidget(parent, f)
+ {
+ }
+
+protected:
+ bool translateKeyEvent(int message, int keycode) const override
+ {
+ if (message >= WM_KEYFIRST && message <= WM_KEYLAST)
+ return true;
+ return QAxWidget::translateKeyEvent(message, keycode);
+ }
+};
+
+#endif // MEDIAAXWIDGET_H
diff --git a/tests/manual/mediaplayer/mediaplayer.pro b/tests/manual/mediaplayer/mediaplayer.pro
new file mode 100644
index 0000000..ad787a3
--- /dev/null
+++ b/tests/manual/mediaplayer/mediaplayer.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+QT += widgets axcontainer
+
+HEADERS = mediaaxwidget.h
+SOURCES = main.cpp
+FORMS = mainwindow.ui
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/mediaplayer
+INSTALLS += target