Open c1ngular opened 4 years ago
i change compile script/init.go a little bit according to the zxing example you gave , it now shows make error info below when i run the init.go file :
`../mpv.cpp:75:22: error: member access into incomplete type 'QQuickWindow' obj->window()->resetOpenGLState(); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ ../mpv.cpp:95:22: error: member access into incomplete type 'QQuickWindow' obj->window()->resetOpenGLState(); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ ../mpv.cpp:152:13: error: member access into incomplete type 'QQuickWindow' window()->setPersistentOpenGLContext(true); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ ../mpv.cpp:153:13: error: member access into incomplete type 'QQuickWindow' window()->setPersistentSceneGraph(true); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ 4 errors generated. make: [mpv.o] Error 1 make: Waiting for unfinished jobs....
exit status 1`
Hey
I look into this and created a new example here: https://github.com/therecipe/qt/tree/master/internal/examples/3rdparty/mpv
To get this working you need to patch the main.cpp
and replace the main function with a small function to register the qml type and also set the locale https://github.com/therecipe/qt/blob/master/internal/examples/3rdparty/mpv/init.go#L42-L43
And also patch the mpvtest.pro
to build a static library instead of an application https://github.com/therecipe/qt/blob/master/internal/examples/3rdparty/mpv/init.go#L38-L39
After building the static lib you can link to it and use the small helper function with something like this: https://github.com/therecipe/qt/blob/master/internal/examples/3rdparty/mpv/mpv.go
You can find the example here, which can be build with go build
or qtdeploy
after you ran the init.go
file.
It did compile for me on arch, but I used a headless docker container and so I'm not sure if this is really working or not.
I initially tried to build this on ubuntu 16.04 and 18.04 but the provided libmpv is a bit dated there, and I didn't want to spend time figuring out which commit I would have to checkout from the "mpv-examles" repo to get it working on these distros.
Hope it works for you though, I will try to setup a arch vm in the next few days to verify that the example is working as expected.
@therecipe thank you for helping out
To get this working you need to patch the main.cpp and replace the main function with a small function to register the qml type and also set the locale https://github.com/therecipe/qt/blob/master/internal/examples/3rdparty/mpv/init.go#L42-L43
And also patch the mpvtest.pro to build a static library instead of an application https://github.com/therecipe/qt/blob/master/internal/examples/3rdparty/mpv/init.go#L38-L39
After building the static lib you can link to it and use the small helper function with something like this: https://github.com/therecipe/qt/blob/master/internal/examples/3rdparty/mpv/mpv.go
Did as your told , but still the exactly same error when ran "init.go":
` ../mpv.cpp:75:22: error: member access into incomplete type 'QQuickWindow' obj->window()->resetOpenGLState(); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ ../mpv.cpp:95:22: error: member access into incomplete type 'QQuickWindow' obj->window()->resetOpenGLState(); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ ../mpv.cpp:152:13: error: member access into incomplete type 'QQuickWindow' window()->setPersistentOpenGLContext(true); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ ../mpv.cpp:153:13: error: member access into incomplete type 'QQuickWindow' window()->setPersistentSceneGraph(true); ^ ../../../therecipe/env_darwin_amd64_513/5.13.0/clang_64/lib/QtQuick.framework/Headers/qquickitem.h:89:7: note: forward declaration of 'QQuickWindow' class QQuickWindow; ^ 4 errors generated.
`
from https://github.com/mpv-player/mpv-examples , it says :
Deprecated opengl-cb API An older variant of the render API is called opengl-cb (in libmpv/opengl_cb.h). It is almost equivalent, but is hardcoded to OpenGL and has some other disadvantages. It is deprecated, and you should use libmpv/render.h instead.
Unfortunately, current libmpv openGL examples still use the deprecated opengl-cb API rather than newer Render API ,so what i have been trying to do so far is in vain for starter like me ,who has no graphic/multimedia programming backgrounds and totally new to QT , since i found this is not a "trivial" job .
Did as your told , but still the exactly same error when ran "init.go":
Sorry, to fix this you just need to add the missing imports to mpv.cpp
#include <QtQuick/QQuickWindow>
#include <QtQuick/QQuickView>
Unfortunately, current libmpv openGL examples still use the deprecated opengl-cb ...
It's usually never really deprecated until it breaks :D also yes, setting up the mpv player is a bit tricky, but once you get it working you probably have the hardest part behind you.
I took another look at your repo and to get this working in this constellation you will need to make the following changes:
diff --git a/init.go b/init.go
index fdc250a..0561d67 100644
--- a/init.go
+++ b/init.go
@@ -1,3 +1,5 @@
+// +build ignore
+
package main
import (
diff --git a/mpv.cpp b/mpv.cpp
index c980435..ba5727c 100644
--- a/mpv.cpp
+++ b/mpv.cpp
@@ -8,7 +8,8 @@
#include <QOpenGLContext>
#include <QtGui/QOpenGLFramebufferObject>
-
+#include <QtQuick/QQuickWindow>
+#include <QtQuick/QQuickView>
namespace
{
diff --git a/mpv.go b/mpv.go
index 80c316e..fc052f2 100644
--- a/mpv.go
+++ b/mpv.go
@@ -2,7 +2,6 @@ package mpv
/*
#cgo pkg-config: mpv
-#cgo linux,amd64 LDFLAGS: -L ${SRCDIR}/mpv-examples/libmpv/qml -lmpvtest
void initMpv();
*/
import "C"
diff --git a/mpv.pro b/mpv.pro
index d03d725..f8533b0 100644
--- a/mpv.pro
+++ b/mpv.pro
@@ -8,5 +8,3 @@ CONFIG += link_pkgconfig debug
PKGCONFIG += mpv
TEMPLATE = lib
CONFIG += staticlib
-TEMPLATE = lib
-CONFIG += staticlib
then create a folder called demo
and add the following files:
[demo/main.go]
package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/quick"
"github.com/c1ngular/mpv"
)
func main() {
gui.NewQGuiApplication(len(os.Args), os.Args)
mpv.InitMpv()
view := quick.NewQQuickView(nil)
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.SetSource(core.NewQUrl3("qrc:/qml/main.qml", 0))
view.Show()
gui.QGuiApplication_Exec()
}
[demo/qml/main.qml] simply use https://github.com/mpv-player/mpv-examples/blob/master/libmpv/qml/main.qml [demo/test.mkv] download http://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv
in the end your directory should look like this:
mpv
├── demo
│ ├── main.go
│ ├── qml
│ │ └── main.qml
│ └── test.mkv
├── init.go
├── mpv.cpp
├── mpv.go
├── mpv.h
├── mpv.pro
├── qthelper.hpp
└── README.md
then cd into github.com/c1ngular/mpv
and run qmake mpv.pro && make mocables
which will create 3 new files
├── Makefile
├── moc_mpv.cpp
├── moc_predefs.h
then cd into the demo folder and run qtdeploy build && ./deploy/linux/demo
@therecipe thank you so much for you help and patience , it is compiling now , i was able to run the example . i will play around it for a while, add features if anything in my reach .
thanks again
No problem, you are welcome :)
I am trying to convert/wrap up this https://github.com/mpv-player/mpv-examples/tree/master/libmpv/qml as a qml media player, but it doesn't compile, complaint about not founding the Quick header files, could anyone take a look for me here : https://github.com/c1ngular/mpv , thanks